[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 而言,它自然也有 ...
随机推荐
- POJ 1080 Human Gene Functions
题意:给两个DNA序列,在这两个DNA序列中插入若干个'-',使两段序列长度相等,对应位置的两个符号的得分规则给出,求最高得分. 解法:dp.dp[i][j]表示第一个字符串s1的前i个字符和第二个字 ...
- HDU 5119 Happy Matt Friends
Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others) Memory Limit: 510000/510000 K (Java/Others ...
- java web 学习十五(jsp基础语法)
任何语言都有自己的语法,JAVA中有,JSP虽然是在JAVA上的一种应用,但是依然有其自己扩充的语法,而且在JSP中,所有的JAVA语句都可以使用. 一.JSP模版元素 JSP页面中的HTML内容称之 ...
- 编写一个循环将list容器的元素逆序输出
<c++ primer>P270,习题9.9 实现代码如下: #include<iostream> #include<list> using namespace s ...
- Linux下用Intel编译器编译安装NetCDF-Fortan库(4.2以后版本)
本来这个问题真的没必要写的,可是真的困扰我太久%>_<%,决定还是记录一下. 首先,最权威清晰的安装文档还是官方的: Building the NetCDF-4.2 and later F ...
- CSS基础(背景、文本、列表、表格、轮廓)
CSS 背景属性 属性 描述 background 简写属性,作用是将背景属性设置在一个声明中. background-attachment 背景图像是否固定或者随着页面的其余部分滚动. backgr ...
- YARN应用场景、原理与资源调度
1.Hadoop YARN产生背景 源于MapReduce1.0 运维成本 如果采用“一个框架一个集群”的模式,则可能需要多个管理员管理这些集群,进而增加运维成本,而共享模式通常需要少数管理员即可完成 ...
- poj1001 Exponentiation
Description Problems involving the computation of exact values of very large magnitude and precision ...
- 执行原始的 SQL 查询
The Entity Framework Code First API includes methods that enable you to pass SQL commands directly t ...
- 5个Xcode开发调试技巧
转自Joywii的博客,原文:Four Tips for Debugging in XCode Like a Bro 1.Enable NSZombie Objects(开启僵尸对象) Enab ...