標籤:多個參數 button out 結果 ui-router ram params 編輯 資料
anuglar.js ui-router 傳遞參數的方法有:
一: ui-sref 傳遞參數,傳遞一個參數的時候
首先路有這樣寫:
.state(‘edit‘, { //線路編輯頁面url: ‘/edit?id‘,templateUrl: ‘view/template/shopList/edit.html‘,controller: ‘editCtrl‘})
html 頁面寫法為:
<button ui-sref="edit({id:{{item.id}}})" type="button" class="btn btn-link btn-sm">編輯</button>
{{item.id}}是動態資料
controller 中擷取傳遞的參數的方法
$state.params.id可以列印 $state.params 看看結果
傳遞多個參數的時候:
路由的寫法為:
.state(‘edit‘, { //線路編輯頁面 url: ‘/edit?id&page‘, templateUrl: ‘view/template/shopList/edit.html‘, controller: ‘editCtrl‘ })url: ‘/edit?id&page‘,需要傳遞多少參數,便在問號後邊跟上就行
html 頁面寫法為:
<button ui-sref="edit({id:{{item.id}},page:{{item.id}}})" type="button" class="btn btn-link btn-sm">編輯</button>
controller 中擷取傳遞的參數的方法,還是跟以前一樣。
一:$state.go 傳遞參數,傳遞一個或者多個參數的時候(直接寫多個一個和 ui-sref 一樣的寫法)
路由寫法
.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
anuglar.js ui-router傳遞參數