当我们使用angularjs的路由时,时常会出现一个需求,当选中菜单时把当前菜单的样式设置为选中状态(多数就是改变颜色)



接下来就看看Angular-UI-Router里的指令ui-sref-active 的使用

其意思就是查看当前激活状态并设置 Class

代码:

<!DOCTYPE html>
<html ng-app="app">
<head>
<title>嵌套视图</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet"
href="../../plugins/bootstrap/css/bootstrap.min.css" type="text/css"></link>
<style type="text/css">
.active1 {
background-color: green!important;
}
</style>
</head>
<body>
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<ul class="nav navbar-nav"> <li ui-sref-active="active1" class=""><a class="navbar-brand" ui-sref="index1"
>index1</a>
</li>
<li ui-sref-active="active1"><a class="navbar-brand" ui-sref="index2"
>index2</a>
</li>
<li ui-sref-active="active1"><a class="navbar-brand" ui-sref="index3"
>index3</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
<div ui-view></div>
</body>
<script type="text/javascript"
src="../../plugins/angular/angular.min-1.4.6.js"></script>
<script type="text/javascript"
src="../../plugins/angular/angular-ui-router-0.2.10.js"></script>
<script type="text/javascript">
var app = angular.module("app", [ 'ui.router' ]);
app.config(
[ '$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
$stateProvider.state('index2', {
url : '/index2',
templateUrl : '/Angular/uiview/nested/index2.html'
}).state('index1', {
url : '/index1',
templateUrl : '/Angular/uiview/nested/index1.html'
}).state('index3', {
url : '/index3',
templateUrl : '/Angular/uiview/nested/index3.html'
});
$urlRouterProvider.otherwise('/index2');
} ]).config(function($sceProvider) {
$sceProvider.enabled(false);
});
app.controller("view1_controller", function($stateParams) {
alert($stateParams.param)
})
</script>
</html>

当我们点击index3跳转到index3页面时,菜单为选中状态。实际上是设置了ui-sref-active="active1"当选中后当前li标签的class被设置为active1,就是自己定义的actice1的样式



[置顶] AngularJS实战之路由ui-sref-active使用的更多相关文章

  1. AngularJS实战之路由ui-view传参

    angular路由传参 首页 <!DOCTYPE html> <html ng-app="app"> <head> <title>路 ...

  2. AngularJS实战之路由ui-view

    1. 路由(ui-router) 1.1. 环境 1) angular.min.js 2) angular-ui-router-0.2.10.js 3) 确保确保包含ui.router为模块依赖关系. ...

  3. 算法代码[置顶] 机器学习实战之KNN算法详解

    改章节笔者在深圳喝咖啡的时候突然想到的...之前就有想写几篇关于算法代码的文章,所以回家到以后就奋笔疾书的写出来发表了 前一段时间介绍了Kmeans聚类,而KNN这个算法刚好是聚类以后经常使用的匹配技 ...

  4. [置顶] 【IOS】IOS7 UI适配

    昨天下了把手机升级成了IOS7 正式版,然后下了最新的xocde5.  试着编译了一下刚刚完成的几个应用,还好问题不大,半个小时的时间都适配好了,然后改了下几个新出现的warning.过几天等空了,要 ...

  5. [置顶] JQuery实战总结三 标签页效果图实现

    在浏览网站时我们会看到当我们鼠标移到多个选项卡上时,不同的选项卡会出现自己对应的界面的要求,在同一个界面上表达了尽量多的信息.大大额提高了空间的利用率.界面的切换效果也是不错的哦,这次自己可以实现啦. ...

  6. AngularJS实战之Controller之间的通信

    我们时常会在不同controller之间进行通信,接下来就介绍三种controller之间的通信方式 一.使用$on.$emit和$broadcast进行controller通信 虽然AngularJ ...

  7. AngularJS ui-router (嵌套路由)

    http://www.oschina.net/translate/angularjs-ui-router-nested-routes AngularJS ui-router (嵌套路由) 英文原文:A ...

  8. [转]AngularJS ui-router (嵌套路由)

    本文转自:http://www.oschina.net/translate/angularjs-ui-router-nested-routes http://www.codeproject.com/A ...

  9. 《AngularJs实战》学习笔记(慕课网)

    1. Controller使用过程中的注意点 不要试图去复用Controller, 一个控制器一般只负责一小块视图 不要在Controller中操作DOM, 这不是控制器的职责. 封装在指令里. 不要 ...

随机推荐

  1. php libev扩展使用

    在WorkerMan源码分析 - 实现最简单的原型文章中提到了libevent网络库,前者和libev都是事件驱动编程库高性能.简单说libev对libevent做了改进和精简.libevent使用全 ...

  2. coding利用Webhook实现Push代码后的jenkins自动构建

    安装jenkins 篇:http://www.cnblogs.com/loveyouyou616/p/8714544.html 之前部署了持续集成工具jenkins.通常是开发后的代码先推到 远程代码 ...

  3. JwtBearerAppBuilderExtensions.UseJwtBearerAuthentication(IApplicationBuilder

    netcore从1.1升级到2.0时,出的错,因为使用的时Jwt token参考https://github.com/aspnet/Security/issues/1310#issuecomment- ...

  4. localstorage和vue结合使用

    父组件 <template> <div class="hello"> <p>Original message:"{{message}} ...

  5. javascript 字面量 和变量 之间的关系

    https://www.w3cschool.cn/javascript/js-syntax.html

  6. 对于读txt文件一点总结

    txt 内容 中间有比如如空格,制表符(tab)在txt为空格符(Spaces).回车符.换行符,有空字符串等情况,在读取过滤中要充分考虑到 1:打开文件 var sr=new StreamReade ...

  7. 超详细的PS抠图方法

    步骤: 1.打开图片,根据图片的特点选择抠图工具: 2.在图像上找到第一个定点,要求定点要完全暴露在画布中,并且是清晰可见的顶点: 3.抠取图像时,多边形套索的定点以及边线应该向内1-2个像素,为了避 ...

  8. python的杨辉三角

    # # / \ # # / \ / \ # # / \ / \ / \ # # / \ / \ / \ / \ # # / \ / \ / \ / \ / \ # # ---------------- ...

  9. PHP字符串位置相关的函数

    strpos函数 描述:将返回一个字符串在另一个字符串第一次出现的位置 语法:int strpos(string haystack, mixed needle [,int offset]); 相反地 ...

  10. 还一道区间DP -- MZOJ 1346: 不老的传说

    http://10.37.2.111/problem.php?id=1346 与上一道染色基本一样,就加了个限制条件(一次最多刷maxd) #include <bits/stdc++.h> ...