anuglar.js ui-router傳遞參數

來源:互聯網
上載者:User

標籤:多個參數   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傳遞參數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.