[AngularJS] ui-router: Abstract States

ui-router has the powerful ability to define abstract states, or states that can‘t be navigated to, but are useful for defining a set of states with shared properties.

angular.module("auth", [])

    .config(function ($stateProvider) {

      $stateProvider
          .state(‘in‘, {
            url: ‘/in‘,
            template: ‘<h1>Sign In</h1>‘ +
                ‘<button class="btn btn-primary" ng-click="signIn()">Sign In Now</button>‘
          })
          .state(‘up‘, {
            url: ‘/up‘,
            template: ‘<h1>Sign Up for a Free Account.</h1>‘
          })
    });    

For example, the sign in page an sign up page share the same content. Those content can be written into the abstract ui router.

angular.module("auth", [])

    .config(function ($stateProvider) {

      $stateProvider
          .state(‘sign‘, {
            abstract: true,
            url: ‘/sign‘,
            template: ‘<a ui-sref=".in">Sign In</a>‘ +
                ‘<a ui-sref=".up">Sign Up!</a>‘ +
                ‘<ui-view/>‘,
            controller: function($scope, authService){
              $scope.signIn = function(){
                authService.signIn();
              }
            },
            resolve: {},
            data: {},
            onEnter: function(){},
            onExit: function(){}
          })
          .state(‘sign.in‘, {
            url: ‘/in‘,
            template: ‘<h1>Sign In</h1>‘ +
                ‘<button class="btn btn-primary" ng-click="signIn()">Sign In Now</button>‘
          })
          .state(‘sign.up‘, {
            url: ‘/up‘,
            template: ‘<h1>Sign Up for a Free Account.</h1>‘
          })
    });
时间: 2025-01-02 01:26:28

[AngularJS] ui-router: Abstract States的相关文章

Angularjs ui router,路由嵌套 父controller执行问题

路由路径设置:structured.text   :structured是第一层路由,text是第二层路由: 问题如下,当$state.transitionTo路由到第二层是,structured的controller也会执行一次,导致页面控件重新加载刷新. $state.transitionTo( "structured.text", { args : $stateParams }, { reload: false} ); 查了github看到 https://github.com/

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

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 实现表单向导

本文转自:http://www.oschina.net/translate/angularjs-multi-step-form-using-ui-router 今天我们将使用AngularJs和伟大的UI Router以及Angular ngAnimate module创建一个带动画的多步表单.这项技术可以用在你想要简化用户操作的大表单上. 我们看到这项技术已经应用在了许多的网页上.比如购物车,注册表单,入职流程以及许多多步表单,让用户更容易在线填写表单. 下面我们将构建它: 使用UI Rout

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">

[AngularJS] Consistency between ui-router states and Angular directives

ui-router's states and AngularJS directives have much in common. Let's explores the similarities between the two and how these patterns have emerged in Angular. Keeping your states and directives consistent can also help with refactoring as your app

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

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

使用angularjs ui grid 动态加载列名

来个开场白吧: 我是做.net开发的,来到新公司后,缺一个前端开发,SO,我就不得不挠着头干活呀......之前也就写写js,jq,刚看到前端架构的时候一脸懵逼...心里就有三个字:什么鬼!什么angularjs,angularjs ui grid,bootstrap,阿西吧.. 木有办法,总不能又跳槽吧.熟悉了一两天业务和代码后,经理说:"开干!". 首先,做的第一个功能就是使用angularjs ui grid 动态加载列.(这里不得不吐槽一点,ui grid的官方文档实例太少了,

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