Angular中ui-router实现路由嵌套案例

学习 ui-router 资料整理

对于Angular内置的路由是单路由视图,ui-router可以实现路由嵌套。后面将会有一个案例概括前面所有资料整理

学习 ui-router - 管理状态  http://bubkoo.com/2014/01/01/angular/ui-router/guide/state-manager/

学习 ui-router - 状态嵌套和视图嵌套  http://bubkoo.com/2014/01/01/angular/ui-router/guide/nested-states%20&%20nested-views/
学习 ui-router - 多个命名的视图  http://bubkoo.com/2014/01/01/angular/ui-router/guide/multiple-named-views/

ui-router 多个命名的视图

<!-- index.html (root unnamed template) -->
<body ng-app>
<div ui-view></div> <!-- contacts.html plugs in here -->
<div ui-view="status"></div>
</body>
<!-- contacts.html -->
<h1>My Contacts</h1>
<div ui-view></div>
<div ui-view="detail"></div>
<!-- contacts.detail.html -->
<h1>Contacts Details</h1>
<div ui-view="info"></div> 

ui-router 相对命名与绝对命名 写法

$stateProvider
  .state(‘contacts‘, {
    // 根状态,对应的父模板则是index.html
    // 所以 contacts.html 将被加载到 index.html 中未命名的 ui-view 中
    templateUrl: ‘contacts.html‘
  })
  .state(‘contacts.detail‘, {
    views: {
        // 嵌套状态,对应的父模板是 contacts.html
        // 相对命名
        // contacts.html 中 <div ui-view=‘detail‘/> 将对应下面
        "detail" : { },   

        // 相对命名
        // 对应 contacts.html 中的未命名 ui-view <div ui-view/>
        "" : { },
        // 绝对命名
        // 对应 contacts.detail.html 中 <div ui-view=‘info‘/>
        "[email protected]" : { }
        // 绝对命名
        // 对应 contacts.html 中 <div ui-view=‘detail‘/>
        "[email protected]" : { }
        // 绝对命名
        // 对应 contacts.html 中的未命名 ui-view <div ui-view/>
        "@contacts" : { }
        // 绝对命名
        // 对应 index.html 中 <div ui-view=‘status‘/>
        "[email protected]" : { }
        // 绝对命名
        // 对应 index.html 中 <div ui-view/>
        "@" : { }
  });

ui-router  实现视图与路由深层嵌套综合案例

源代码下载请点击

作者:Avenstar

出处:http://www.cnblogs.com/zjf-1992/p/6509814.html

关于作者:专注于前端开发

本文版权归作者所有,转载请标明原文链接

时间: 2024-08-22 19:33:08

Angular中ui-router实现路由嵌套案例的相关文章

Angularjs中UI Router全攻略

摘自:Angularjs中UI Router全攻略 温馨提示:想要了解 angular-ui-router的同学,从上往下读一遍,能带随着coding那就更好了,保证你对angular-ui-router基本全部掌握. 如何引用依赖angular-ui-router angular.module('app',["ui.router"]) .config(function($stateProvider){ $stateProvider.state(stateName, stateCofi

Angularjs中UI Router用法小记录

今天自己参考已有的项目代码学习了下UI Router的用法,写了个小demo,验证了下自己的想法,现把使用情况记录一下. 1.入口文件index.html,引入项目所需的js文件,标注ng-app,创建ui-view元素,为后面的嵌套做容器准备. <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8">

angular 的ui.router 定义不同的state 对应相同的url

Angular UI Router: Different states with same URL? The landing page of my app has two states: home-public, home-logged-in. Now I want to show both states on the same URL, but let the controller and template depend on the user session (is the user log

angular中ui calendar的一些使用心得

ui calendar是封装fullcalendar的一款angular指令插件 官方地址:http://angular-ui.github.io/ui-calendar/ fullcalendar 和ui calendar包安装我就不介绍了.自行百度下. 包安装好后,添加路径引用 本次开发环境angular1.x 调用 <div ui-calendar="uiConfig.calendar" class="span8 calendar" ng-model=&

vue中this.$router.push()路由传值和获取的两种常见方法

1.路由传值   this.$router.push() (1) 想要导航到不同的URL,使用router.push()方法,这个方法会向history栈添加一个新纪录,所以,当用户点击浏览器后退按钮时,会回到之前的URL (2)当点击 <router-link> 时,这个方法会在内部调用,即点击 <router-link :to="..."> 等同于调用 router.push(...) a)      声明式:<router-link :to=&quo

Vue中使用children实现路由的嵌套

Vue中使用children实现路由的嵌套 相关Html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv=&

angular : $location &amp; $state(UI router)的关系

次序:angular 的 location会先跑 $rootScope.$on("$locationChangeStart", function (scope, newUrl, oldUrl) { log("$locationChangeStart from " + oldUrl) log("$locationChangeStart to " + newUrl) }); 接着是 ui router $state $rootScope.$on(&q

AngularJS的增删改查、state嵌套案例,不涉及服务端

本篇实践一个案例,大致是:左边有导航菜单,右边显示列表,并可对列表项编辑或删除,也可添加新的列表项.借此,可体会到:如何组织可扩展的AngualrJS文件结构,如何点击左侧菜单项右侧显示相应内容,angular-ui-router的使用以及嵌套state,增删改查,等等. 大致如下: 当点击添加按钮: 当点击更新按钮: 文件结构 node_modules/src/.....app/..........categories/  ...............categories.js  <包含一个

ngRoute 和 ui.router 的使用方法和区别

在单页面应用中要把各个分散的视图给组织起来是通过路由机制来实现的.本文主要对 AngularJS 原生的 ngRoute 路由模块和第三方路由模块 ui.router 的用法进行简单介绍,并做一个对比. ngRoute 使用方法 1) 引入 angular-route lib 无论是 ngRoute 还是 ui.router ,作为框架额外的附加功能,都必须以 模块依赖 的形式被引入. 1 <script src="lib/angular-route.js"></sc