angular.js学习 ui-router 0.2.15

1.  ui-router 是以状态驱动的,一个状态等价于该应用内的一个ui部分。

2,使用实例如下,当一个状态被激活后,它所代表的模板html就会被插入到ui-view中。

  

<!-- in index.html -->
<body ng-controller="MainCtrl">
  <section ui-view></section>
</body>
var  myApp = angular.module( "myApp" , [&apos;ui.router&apos;]);
myApp.config( function  ($stateProvider, $urlRouterProvider) {
      $urlRouterProvider.when( "" "/PageTab" );
      $stateProvider
         .state( "PageTab" , {
             url:  "/PageTab" ,
             templateUrl:  "PageTab.html"
         })
         .state( "PageTab.Page1" , {
             url: "/Page1" ,
             templateUrl:  "Page1.html"
         })
});
 
    

 

3.  如何激活一个state,方法有三:

  1.调用$state.go(to [, toParams] [, options]),to参数是以".”来分隔父状态和子状态

  • $state.go('contact.detail') 将会跳到 'contact.detail'状态
  • $state.go('^') 将会跳到父状态.
  • $state.go('^.sibling') 将会跳到兄弟状态.
  • $state.go('.child.grandchild') 将会跳到子孙状态.
  1. $state.go()
  2. Click a link containing the ui-sref directive. Learn More
  3. Navigate to the url associated with the state. Learn More

4. 如何定义state对应的template

$stateProvider.state('contacts', {   // 直接写入template内容
  template: '<h1>My Contacts</h1>'
})

$stateProvider.state('contacts', {
  templateUrl: 'contacts.html'      // 填写template文件地址
})

$stateProvider.state('contacts', {
  templateUrl: function ($stateParams){
    return '/partials/contacts.' + $stateParams.filterBy + '.html'; //template是一个function 返回值为template文件地址
  }
})

$stateProvider.state('contacts', {
  templateProvider: function ($timeout, $stateParams) {
    return $timeout(function () {
      return '<h1>' + $stateParams.contactId + '</h1>'     
    }, 100);
  }
})

 

posted on 2015-11-09 08:27  梦见世界 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lifeisshort/p/4948949.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值