angularJs中ui.route的簡單應用

來源:互聯網
上載者:User

標籤:angular   params   module   conf   ons   app.js   lis   javascrip   簡單   

  html頁面代碼
<body ng-app="myApp">  <div ui-view></div>  <div ui-view="login"></div>  <div ui-view="enroll"></div></body>

需要引用的ui.router.js檔案

<script src="angular-ui-router.js"></script>

 

app.js

將UI-Router作為web應用的依賴,注入到主程式:

url:url選項將會為該應用的狀態指定一個URL基於使用者瀏覽該應用所在的狀態(地址顯示連結)。這樣當在瀏覽該應用的時候便能實現深度連結的效果。 

var myApp = angular.module(‘myApp‘, [‘ui.router‘]);myApp.config([‘$stateProvider‘, ‘$urlRouterProvider‘, routeConfig]);function routeConfig($stateProvider, $urlRouterProvider) {  $urlRouterProvider.otherwise(‘‘);  $stateProvider.state(‘competition‘, {    url: ‘/competition‘,    templateUrl: ‘/competition.html‘,    controller: ‘competitionController‘  }).state(‘competition.detail‘, {    url: ‘/competition-detail‘,    templateUrl:  ‘/competition-detail.html‘,    controller: ‘competitionDetailController‘  }).state.(‘competition.enrollForm‘,{    url: ‘/competition.enrollForm‘,    templateUrl:  ‘competition-enrollFrom.html‘,    controller: ‘enrollFromController‘  }).state.(‘competition.comments‘,{    url: ‘/competition-comments‘,    templateUrl:  ‘competition-comments.html‘,    controller: ‘commentsController‘  }).state(‘competition.login‘,{    url: ‘/competition-login‘,    views: {      ‘[email protected]‘: {        templateUrl:  ‘competition-login.html‘,        controller: ‘loginController‘      }    }  }).state(‘competition.enroll‘,{
  url: ‘/competition-enroll‘,
views: {
    ‘[email protected]‘: {
     templateUrl: ‘competition-enroll.html‘,
      controller: ‘enrollController‘
}
}
})
}

需要注意的是:ui.router使用的是$stateProvider,ngRoute使用的是$routeProvider。

$state.go

$state.go(to, [,toParams],[,options])
形參to是string類型,必須,使用"^"或"."表示相對路徑;
形參toParams可空,類型是對象;
形參options可空,類型是對象,欄位包括:location為bool類型預設true,inherit為bool類型預設true, relative為對象預設$state.$current,notify為bool類型預設為true, reload為bool類型預設為false

$state.go(‘photos.detail‘)
$state.go(‘^‘)到上一級,比如從photo.detail到photo
$state.go(‘^.list‘)到相鄰state,比如從photo.detail到photo.list
$state.go(‘^.detail.comment‘)到孫子級state,比如從photo.detail到photo.detial.comment

如有錯誤還請及時指出

 

 

 

angularJs中ui.route的簡單應用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.