Angular 学习笔记 6

例子4 多视图

 angular.module('myApp', ['ui.router'])
            .config(function ($stateProvider) {
                $stateProvider
                        .state('state', {
                            url: '/state',
                            views: {
                                'view1': {
                                    template: '<strong>{{text}}</strong>',
                                    controller: function ($scope) {
                                        $scope.text = "This is view1.";
                                    }
                                },
                                'view2': {
                                    template: '<strong>{{text}}</strong>',
                                    controller: function ($scope) {
                                        $scope.text = "This is view2.";
                                    }
                                }
                            }
                        })
            })
    ;
<div ng-app="myApp">
    <div ui-view="view1">This div will be replaced.</div>
    <div ui-view="view2">This div will be replaced too.</div>
</div>


例子5  $urlRouterProvider

 angular.module('myApp', ['ui.router'])
            .config(function ($urlRouterProvider, $stateProvider) {
                $urlRouterProvider.when('', '/state')   // 重定向
                        .otherwise('');                 // 当没有其他路由匹配时,重定向
                $stateProvider
                        .state('state', {
                            url: '/hello',
                            template: '<div>This is the template.</div>'
                        })
            })
    ;
<div ng-app="myApp">
    <div ui-view>This div will be replaced.</div>
</div>

例子6 继承状态以及嵌套视图

  angular.module('myApp', ['ui.router'])
            .config(function ($stateProvider) {
                $stateProvider
                        .state('father', {
                            abstract: true,
                            url: '/father',
                            template: '<div>father</div>' +
                            '<div ui-view></div>'
                        })
                        .state('father.child1', {
                            url: '/child1',
                            template: '<div>This is child1</div>'
                        })
                        .state('father.child2', {
                            url: '/child2',
                            template: '<div>This is child2</div>'
                        })
            })
    ;
<div ng-app="myApp">
    <div ui-view>This div will be replaced.</div>
</div>

这样一来,ui-router 就学的差不多了。





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值