[AngularJS] ui-router: named views
The ui-router library for AngularJS provides the ability to name views within your application. This is useful for dividing up your application into sections, and changing the content of a section based on the current state.
We use named view to build a simple webpage with 'header','sidebar','content' and 'footer'.
/**
* Created by Answer1215 on 12/17/2014.
*/
angular.module('app', ['ui.router'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: '/',
views: {
'header': {
templateUrl: 'app/common/header.tpl.html'
},
'sidebar': {
templateUrl: 'app/common/sidebar.tpl.html'
},
'content': {
templateUrl: 'app/common/content.tpl.html'
},
'footer': {
templateUrl: 'app/common/footer.tpl.html'
}
}
});
$urlRouterProvider.otherwise('/');
});
<div class="container"> <!-- Header -->
<div ui-view="header" class="row"></div> <div class="row">
<!-- Sidebar/Nav -->
<div ui-view="sidebar" class="col-xs-3"></div>
<!-- Content -->
<div ui-view="content" class="col-xs-9"></div>
</div> <!-- Footer -->
<div ui-view="footer" class="row"></div>
</div>
Result:
Now when we click 'One', 'Two' and 'Three', we also want to replace the content accordingly.
alt-one.js:
/**
* Created by Answer1215 on 12/17/2014.
*/
angular.module('app.alt-one', ['ui.router'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app.alt-one', {
url: 'alt-one',
views: {
// '@': replace the content
// if there is just @ without other stuff, it will looking for the parent 'app' root
'content@': {
templateUrl: 'app/alt-one/alt-one.content.tpl.html'
}
}
})
})
alt-two.js: we replace the content and header both at the same time.
/**
* Created by Answer1215 on 12/17/2014.
*/
angular.module('app.alt-two', ['ui.router'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app.alt-two', {
url: 'alt-two',
views: {
'content@': {
templateUrl: 'app/alt-two/alt-two.content.tpl.html'
},
'header@': {
templateUrl: 'app/alt-two/alt-two.header.tpl.html'
}
}
})
})
alt-three.js:
/**
* Created by Answer1215 on 12/17/2014.
*/
angular.module('app.alt-three', [
'ui.router'
])
.config(function($stateProvider) {
$stateProvider
.state('app.alt-three', {
url: 'alt-three',
views: {
'content@': {
templateUrl: 'app/alt-three/alt-three.content.tpl.html'
},
'header@': {
templateUrl: 'app/alt-three/alt-three.header.tpl.html'
},
// find the 'alt-three' directory to replace the name view == "one"
'one@app.alt-three': {
template: '<div class="alert-info">Sub One</div>'
},
// find the 'alt-three' directory to replace the name view == "two"
'two@app.alt-three': {
template: '<div class="alert-success">Sub Two</div>'
}
}
}
)
})
;
Read More: https://egghead.io/lessons/angularjs-ui-router-named-views
[AngularJS] ui-router: named views的更多相关文章
- angularJS ui router 多视图单独刷新问题
场景:视图层级如下 view1 --view11 --view111 需求:view11的一个动作过后,单独刷新view12 解决方式:修改层级设计 view1 --view11 --view111 ...
- [转]AngularJS+UI Router(1) 多步表单
本文转自:https://www.zybuluo.com/dreamapplehappy/note/54448 多步表单的实现 在线demo演示地址https://rawgit.com/dream ...
- Angularjs ui router,路由嵌套 父controller执行问题
解决方式来源:https://stackoverflow.com/questions/25316591/angularjs-ui-router-state-reload-child-state-onl ...
- AngularJS 使用 UI Router 实现表单向导
Today we will be using AngularJS and the great UI Router and the Angular ngAnimate module to create ...
- [Angular-Scaled web] 4. Using ui-router's named views
In the previous post, we use $stateProvider deriect to root url and using MainCtrl, categories.tmpl. ...
- [转]AngularJS 使用 UI Router 实现表单向导
本文转自:http://www.oschina.net/translate/angularjs-multi-step-form-using-ui-router 今天我们将使用AngularJs和伟大的 ...
- angularjs ngRoute和ui.router对比
ngRoute模块是angularjs自带的路由模块,ui.router是一个第三方路由模块,接下来将对两者进行一个对比: ng-router(angular-router.js) ng-view n ...
- 【原创】ui.router源码解析
Angular系列文章之angular路由 路由(route),几乎所有的MVC(VM)框架都应该具有的特性,因为它是前端构建单页面应用(SPA)必不可少的组成部分. 那么,对于angular而言,它 ...
- ngRoute 与ui.router区别
angular路由 路由 (route) ,几乎所有的 MVC(VM) 框架都应该具有的特性,因为它是前端构建单页面应用 (SPA) 必不可少的组成部分. 那么,对于 angular 而言,它自然也有 ...
随机推荐
- ASP.NET MVC+Bootstrap个人博客之praise.js点赞特效插件(二)
1. 为啥要做这个点赞插件? praise.js是一款小巧的jQuery点赞插件,使用简便,效果美观. 在做个人博客时遇到了文章点赞问题.联想到各大社交网络中的点赞特效:手势放大.红心放大等等, ...
- wireshark tcp 协议分析 z
虽然知道wireshark是抓包神器,只会大概大概用一下,还用一下下tcpdump,略懂一点BPF过滤器,也知道一点怎么用 wirkshark过滤相关的报文,但是对于详细的字段的含义,如何查看TCP的 ...
- HDU 3695-Computer Virus on Planet Pandora(ac自动机)
题意: 给一个母串和多个模式串,求模式串在母串后翻转后的母串出现次数的的总和. 分析: 模板题 /*#include <cstdio> #include <cstring> # ...
- HDU5715 XOR 游戏 二分+字典树+dp
当时Astar复赛的时候只做出1题,赛后补题(很长时间后才补,懒真是要命),发现这是第二简单的 分析: 这个题,可以每次二分区间的最小异或和 进行check的时候用dp进行判断,dp[i][j]代表前 ...
- LoadRunner学习记录--Flights打开空白页的问题
从网上查了一下,原因是PERL5LIB这个环境变量的原因. 担心修改环境变量会影响ORACLE的运行 在WebTour中修改run.bat 增加 set PERL5LIB=D:\oracle\pr ...
- MockMvc和Mockito之酷炫使用
由于项目中需要添加单元测试,所以查询之后发现Mockito非常适合现在的web项目. 首先需要添加pom依赖: <dependency> <groupId>junit</ ...
- 《浅析各类DDoS攻击放大技术》
原文链接:http://www.freebuf.com/articles/network/76021.html FreeBuf曾报道过,BT种子协议家族漏洞可用作反射分布式拒绝服务攻击(DRDoS a ...
- SSH无法连接服务器
服务器版本如下: @kelWEB4:/etc# lsb_release -a LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd ...
- 怎么对HTML 5的特性做检测?
原译文地址:http://www.ido321.com/1116.html 原文:Detect HTML5 Features 译文:HTML5特性检测 译者:dwqs 随 着HTML 5的流行,现在H ...
- Windows Azure 不能ping通的解决方案
Windows Azure 不能ping通如何解决? 为了避免Ping Flood攻击,Windows Azure不开放对外ICMP通讯协定,所以使用ping命令我们是无法ping通的.在微软资料中心 ...