AngularJS-UI-Router
涉及知识点:
$stateProvider,$urlRouteProvider
ui-href
$stateParams,$state
1.如何引用依赖angular-ui-router
angular.module('app',["ui.router"])
.config(function($stateProvider){
$stateProvider.state(stateName, stateCofig);
})
2.ui-router配置路由$stateProvider
.config(function($stateProvider) {
$stateProvider.state('dashboard.home', {
url: '/home',
views: {
"content": {
controller: 'HomeCtrl',
templateUrl: 'dashboard/home/home.tpl.html'
}
},
data: { pageTitle: 'Home' },
restricted: true
});
})
具体参数:$stateProvider.state(stateName, stateConfig)
stateName是string类型,stateConfig是object类型
stateConfig包含的字段:template, templateUrl, templateProvider, controller, controllerProvider, resolve, url, params, views, abstract, onEnter, onExit, reloadOnSearch, data
$stateProvider.state("home",{});//statConfig可以为空对象
//state可以有子父级
$stateProvider.state("home",{});
$stateProvider.state("home.child",{}) $stateProvider.state("home",{}).state("about",{}).state("photos",{});//state可以是链式的
3.$urlRouteProvider
$urlRouteProvider.when(whenPath, toPath)
$urlRouterProvider.otherwise(path)
$urlRouteProvider.rule(handler)
4.$state.go
$state.go(to, [,toParams],[,options])
形参to是string类型,必须,使用"^"或"."表示相对路径;
形参toParams可空,类型是对象;
形参options可空,类型是对象,字段包括:location为bool类型默认true,inherit为bool类型默认true,
relative为对象默认$state.$current,notify为bool类型默认为true, reload为bool类型默认为false
$state.go('photos.detail')
$state.go('^')到上一级,比如从photo.detail到photo
$state.go('^.list')到相邻state,比如从photo.detail到photo.list
$state.go('^.detail.comment')到孙子级state,比如从photo.detail到photo.detial.comment
5.ui-sref
ui-sref='stateName'
ui-sref='stateName({param:value, param:value})'
6.详述
大多数应用中的states有一个url与他们相关联,URL Routing是需要在一开始就设计好的。
基本状态设置:
$stateProvider
.state('contacts', {
url: "/contacts",
templateUrl: 'contacts.html'
})
现在当用户输入index.html/contacts,'contacts' state将会被激活且主的ui-view将会和contacts.html一起生成。另一种方式,如果用户通过transitionTo('contacts')来transition to contact状态,则url将会更新成index.html/contacts。
URL参数
$stateProvider
.state('contacts.detail', {
url: "/contacts/:contactId",
templateUrl: 'contacts.detail.html',
controller: function ($stateParams) {
// If we got here from a url of /contacts/42
expect($stateParams).toBe({contactId: "42"});
}
})
或者可以选用花括号形式,效果是一样的:
url: "/contacts/{contactId}"
例子:
'/hello/' //Matches only if the path is exactly '/hello/'. There is no special treatment for trailing slashes, and patterns have to match the entire path, not just a prefix.
'/user/:id' //Matches '/user/bob' or '/user/1234!!!' or even '/user/' but not '/user' or '/user/bob/details'. The second path segment will be captured as the parameter 'id'.
'/user/{id}' //Same as the previous example, but using curly brace syntax.
'/user/{id:int}' //The param is interpreted as Integer.
在link中使用parameters
<a ui-sref="contacts.detail({contactId: id})">View Contact</a>
参考URL:
http://www.cnblogs.com/littlemonk/p/5500801.html
https://github.com/angular-ui/ui-router/wiki/URL-Routing
http://www.cnblogs.com/littlemonk/p/5484322.html
AngularJS-UI-Router的更多相关文章
- [转]AngularJS+UI Router(1) 多步表单
本文转自:https://www.zybuluo.com/dreamapplehappy/note/54448 多步表单的实现 在线demo演示地址https://rawgit.com/dream ...
- angularJS ui router 多视图单独刷新问题
场景:视图层级如下 view1 --view11 --view111 需求:view11的一个动作过后,单独刷新view12 解决方式:修改层级设计 view1 --view11 --view111 ...
- Angularjs ui router,路由嵌套 父controller执行问题
解决方式来源:https://stackoverflow.com/questions/25316591/angularjs-ui-router-state-reload-child-state-onl ...
- angularjs ngRoute和ui.router对比
ngRoute模块是angularjs自带的路由模块,ui.router是一个第三方路由模块,接下来将对两者进行一个对比: ng-router(angular-router.js) ng-view n ...
- AngularJS 使用 UI Router 实现表单向导
Today we will be using AngularJS and the great UI Router and the Angular ngAnimate module to create ...
- [转]AngularJS 使用 UI Router 实现表单向导
本文转自:http://www.oschina.net/translate/angularjs-multi-step-form-using-ui-router 今天我们将使用AngularJs和伟大的 ...
- ngRoute 和 ui.router 的使用方法和区别
在单页面应用中要把各个分散的视图给组织起来是通过路由机制来实现的.本文主要对 AngularJS 原生的 ngRoute 路由模块和第三方路由模块 ui.router 的用法进行简单介绍,并做一个对比 ...
- angularjs UI Libraries
angularjs UI Libraries ● ng-bootstrap is currently available. ● PrimeNG has largest number of compon ...
- 【原创】ui.router源码解析
Angular系列文章之angular路由 路由(route),几乎所有的MVC(VM)框架都应该具有的特性,因为它是前端构建单页面应用(SPA)必不可少的组成部分. 那么,对于angular而言,它 ...
- angular : $location & $state(UI router)的关系
次序:angular 的 location会先跑 $rootScope.$on("$locationChangeStart", function (scope, newUrl, o ...
随机推荐
- angular学习之关于ng-class详解
1,定义和用法 ng-class 指令用于给 HTML 元素动态绑定一个或多个 CSS 类. ng-class 指令的值可以是字符串,对象,或一个数组. 如果是字符串,多个类名使用空格分隔. 如果是对 ...
- 挑战程序2.1.5 穷竭搜索>>宽度优先搜索
先对比一下DFS和BFS 深度优先搜索DFS 宽度优先搜索BFS 明显可以看出搜索顺序不同. DFS是搜索单条路径到 ...
- Duilib改进窗口拖动,使整个窗口都能拖动两种方法(转载)
转载:http://www.cnblogs.com/XiHua/articles/3490490.html 转载:http://blog.csdn.net/lostspeed/article/deta ...
- MATLAB地图工具箱学习总结(二)大圆和恒向线
MATLAB地图工具箱学习总结(二)大圆和恒向线 今天要和大家谈一谈大圆.恒向线航道的画法.还是先从案例开始说起,再分别介绍相关的函数. 1 作业案例:地图投影作 ...
- linux和android博客链接
1.Tracy Mcgrady的专栏冰山一角:linux和Android底层开发,主要是mtk系列点击打开链接 2.郁闷Wednesday:嵌入式linux 单片机 android,点击打开链接 3. ...
- html5悬浮球效果
自己想做一个自己的网站,觉得自适应的效果会好一点,但是放到手机端的话,菜单显示是个问题.所以自己试着写了一个悬浮球菜单的效果. 好了,上代码. 这里有四个文件要用: jqurey.js//因为基于jq ...
- 渗透测试工具Nmap从初级到高级使用教程
本文由阿德马翻译自国外网站,请尊重劳动成果,转载请注明出处,谢谢 Nmap是一款网络扫描和主机检测的非常有用的工具.Nmap是不局限于仅仅收集信息和枚举,同时可以用来作为一个漏洞探测器或安全扫描器.它 ...
- MySQL初始配置
mysql初始密码在/var/log/mysqld.log中 ,搜索:temporary password #mysql -uroot -p 登录mysql MYSQL密码策略有3级(0,1,2)默认 ...
- Docker安装ruby2.1
# sudo apt-get install Python-software-properties# sudo apt-add-repository ppa:brightbox/ruby-ng# su ...
- 解决IE6,IE7下子元素使用position:relative、父元素使用overflow:auto后,子元素不随着滚动条滚动的问题
解决IE6,IE7下子元素使用position:relative.父元素使用overflow:auto后,子元素不随着滚动条滚动的问题 在IE6,IE7下,子元素使用position:relati ...