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. java - 自己制作一個視頻播放器,遇到問題,用的是內置surfaceview類,具體看代碼!2. javascript - vue 移動端的input 數字輸入優化3. java - mongodb分片集群下,count和聚合統計問題4. java - ehcache緩存用的是虛擬機內存么?5. 服務器端 - 采用nginx做web服務器,C++開發應用程序 出現拒絕連接請求?6. 為什么我ping不通我的docker容器呢???7. 關于docker下的nginx壓力測試8. android - java 泛型不支持數組,那么RxJava的Map集合有什么方便的手段可以定義獲得一串共同父類集合數據呢?9. python - pandas按照列A和列B分組,將列C求平均數,怎樣才能生成一個列A,B,C的dataframe10. javascript - 有什么兼容性比較好的辦法來判斷瀏覽器窗口的類型?
