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 - 阿里的开发手册中为什么禁用map来作为查询的接受类?2. apache - 想把之前写的单机版 windows 软件改成网络版,让每个用户可以注册并登录。类似 qq 的登陆,怎么架设服务器呢?3. 创建mysqli对象与数据库连接 - 出错4. 用Html5怎么实现简单选择排序?5. node.js - win7下,npm 无法下载依赖包,淘宝镜像也装不上,求帮忙???6. mysql 的datadir设置的文件夹不存在,启动了mysql服务后创建的数据库存在哪里?7. mysql 使用group_concat后 顺序改变是怎么回事?8. python - uwsgi+django的搭建问题9. php多任务倒计时求助10. 如何合并两张具有相同结构的mysql表
