anuglar.js ui-router 傳遞參數的方法有:html
一: ui-sref 傳遞參數,傳遞一個參數的時候ui
首先路有這樣寫:url
.state('edit', { //線路編輯頁面 url: '/edit?id', templateUrl: 'view/template/shopList/edit.html', controller: 'editCtrl' })
html 頁面寫法爲:spa
<button ui-sref="edit({id:{{item.id}}})" type="button" class="btn btn-link btn-sm">編輯</button>
{{item.id}}是動態的數據
controller 中獲取傳遞的參數的方法code
$state.params.id 能夠打印 $state.params 看看結果
傳遞多個參數的時候:router
路由的寫法爲:
htm
.state('edit', { //線路編輯頁面 url: '/edit?id&page', templateUrl: 'view/template/shopList/edit.html', controller: 'editCtrl' }) url: '/edit?id&page', 須要傳遞多少參數,便在問號後邊跟上就行
html 頁面寫法爲:blog
<button ui-sref="edit({id:{{item.id}},page:{{item.id}}})" type="button" class="btn btn-link btn-sm">編輯</button>
controller 中獲取傳遞的參數的方法,仍是跟之前同樣。路由
一:$state.go 傳遞參數,傳遞一個或者多個參數的時候(直接寫多個一個和 ui-sref 同樣的寫法)it
路由寫法
.state('home', { url: '/home?id&page', templateUrl: 'view/home.html', controller: 'homeCtrl' })
控制器寫法:
$state.go('home',{id: '01',page: '02'});
接受參數的寫法:
console.log($state.params);接受參數的時候有兩種寫法都是同樣的:$state.params.id 或者 $stateParams.id