angular.js - angularjs標簽切換
問題描述
$scope.peopleprofile = true; $scope.peoplesettings = false; if( $scope.locationpath == ’/peopleProfile’){$scope.peopleprofile = true;$scope.peoplesettings = false; }else if( $scope.locationpath == ’/peopleSettings’){$scope.peoplesettings = true;$scope.peopleprofile = false; } $scope.go = function(url, type){if( type == ’peopleprofile’){ $scope.peopleprofile = true; $scope.peoplesettings = false;}else if( type == ’peoplesettings’){ $scope.peoplesettings = true; $scope.peopleprofile = false;}routeSrvc.go(url); };
<p ng- ng-controller='PersonController'> <a ng-click='go(’peopleProfile’, ’peopleprofile’)'><i class='fa fa-cog'></i>個人設置</a></p><p ng- ng-controller='PersonController'> <a ng-click='go(’peopleSettings’, ’peoplesettings’)'><i class='fa fa-cog'></i>賬號設置</a></p>
默認如下圖:
點賬號設置的時候 我希望當前狀態在賬號設置上 但是效果確是下面這樣子的
路過的幫我看看是什么問題唄,先謝過啦~~~
問題解答
回答1:推薦你使用angular的ui-router,很方便,而且更能十分強大;我看看有沒有時間,幫你寫個小demo。
補充:
抽空幫你寫的一個demo
HTML文件代碼如下:
<body ng-app='MyApp' ng-controller='MyController as vm'> <h1>A demo of ui-router</h1> <ul class='menu'><li class='item'> <a ui-sref='personal-setting' ui-sref-active='item-active'>個人設置</a></li><li class='item'> <a ui-sref='account-setting' ui-sref-active='item-active'>賬號設置</a></li><li class='item'> <a ui-sref='hello-setting' ui-sref-active='item-active'>隨便看看</a></li> </ul> <hr/> <p ui-view>初始化狀態...</p></body>
JS文件代碼如下:
(function(){ angular.module(’MyApp’, [’ui.router’,’ngAnimate’ ]).config(config).controller(’MyController’, MyController); config.$inject = [’$stateProvider’, ’$urlRouterProvider’]; MyController.$inject = []; function config($stateProvider, $urlRouterProvider){$urlRouterProvider.otherwise(’setting/default’);$stateProvider .state(’account-setting’, {url: ’setting/account’,templateUrl: ’template/account-setting.html’ }) .state(’personal-setting’, {url: ’setting/personal’,templateUrl: ’template/personal-setting.html’ }) .state(’hello-setting’, {url: ’setting/hello’,templateUrl: ’template/hello-setting.html’ }) .state(’default-setting’, {url: ’setting/default’,templateUrl: ’template/default-setting.html’ }) } function MyController(){var vm = this; }})();
CSS文件代碼如下:
h1{ text-align: center;}.menu{ list-style: none;}.menu .item{ display: block; width: 80px; height: 30px; margin-top: 2px;}.menu .item a{ display: block; width: 80px; height: 30px; background-color: black; color: red; text-decoration: none; text-align: center; line-height: 30px;}.item-active{ background-color: red !important; color: black !important;}
希望可以幫到你。
回答2:<p ng-controller='PersonController'> <p ng-class='peopleprofile ? ’peoplesetting-nav-style’ : ’peoplesetting-nav’'><a ng-click='go(’peopleProfile’, ’peopleprofile’)'> <i class='fa fa-cog'></i>個人設置</a> </p> <p ng-class='peoplesettings ? ’peoplesetting-nav-style’ : ’peoplesetting-nav’'><a ng-click='go(’peopleSettings’, ’peoplesettings’)'> <i class='fa fa-cog'></i>賬號設置</a> </p></p>回答3:
樓主 ,能不能將你的完整的例子貼出來啊,小弟需要學習一下
相關文章:
1. 我的html頁面一提交,網頁便顯示出了我的php代碼,求問是什么原因?2. 我在centos容器里安裝docker,也就是在容器里安裝容器,報錯了?3. 數據庫 - 使用讀寫分離后, MySQL主從復制延遲會導致讀不到數據嗎?4. tp6表單令牌5. docker 17.03 怎么配置 registry mirror ?6. 老哥們求助啊7. django - 后臺返回的json數據經過Base64加密,獲取時用python如何解密~!8. node.js - node 客戶端socket一直報錯Error: read ECONNRESET,用php的socket沒問題哈。。9. 如何解決docker宿主機無法訪問容器中的服務?10. javascript - canvas 可以實現 PS 魔法橡皮擦的功能嗎?
