Page 366 - AngularJS权威教程
P. 366

346  第 25 章  AngularJS 精华扩展


                         })
                         .state('finish', {
                             url: '/finish',
                             templateUrl: 'partials/wizard/step_3.html'
                         });
                 });
                 设置这些选项之后,基本流程就全部完成了。现在,如果用户导航到路由/step_1,他们将
             被定向到流程的起点。尽管整个流程也可以都发生在根URL上(即/step_1),但你可能更希望将
             它们放在子路由中(例如/wizard/step_1)。

                 为此,只需要设置一个包装其他步骤的abstract状态就可以了。
                 .config(function($stateProvider, $urlRouterProvider) {
                     $stateProvider
                         .state('wizard', {
                             abstract: true,
                             url: '/wizard',
                             template: '<div><div ui-view></div></div>'
                         })
                         .state('wizard.start', {
                             url: '/step_1',
                             templateUrl: 'partials/wizard/step_1.html'
                         })
                         .state('wizard.email', {
                             url: '/step_2',
                             templateUrl: 'partials/wizard/step_2.html'
                         })
                         .state('wizard.finish', {
                             url: '/finish',
                             templateUrl: 'partials/wizard/step_3.html'
                         });
                 });
                 现在,这些路由不再定义在顶级路由中了,你可以将它们(子路由)安全地嵌套在/wizard
             URL内。
                 此外,我们还想在注册程序的尾部附加一个功能:在父控制器WizardSignupController上
             调用signup函数。我们只需在向导程序的尾部设置一个控制器来调用$scope上的函数就行了。
             由于整个向导程序都封装在WizardSignupController中,这就表示可以正常使用作用域嵌套作
             用域属性。

                 .state('wizard.finish',{
                     url: '/finish',
                     templateUrl: 'partials/wizard/step_3.html',
                     controller: function($scope) {
                         $scope.signup();
                     }
                 });


             25.4  ui-utils

                 UI工具库是一个功能强大的实用工具包,它提供了大量可用于你的项目中的自定义扩展,而
             你无需重新造轮子。

                 下面展示了ui-utils库所提供的一些值得注意的特性。
   361   362   363   364   365   366   367   368   369   370   371