在 Angularjs 中 ui-sref 和 $state.go 如何传递参数
生活随笔
收集整理的這篇文章主要介紹了
在 Angularjs 中 ui-sref 和 $state.go 如何传递参数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
1 ui-sref、$state.go 的區別
ui-sref?一般使用在?<a>...</a>;
<a ui-sref="message-list">消息中心</a>$state.go('someState')一般使用在 controller里面;
.controller('firstCtrl', function($scope, $state) {$state.go('login');});這兩個本質上是一樣的東西,我們看ui-sref的源碼:
... element.bind("click", function(e) {var button = e.which || e.button;if ( !(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || element.attr('target')) ) {var transition = $timeout(function() {// HERE we call $state.go inside of ui-sref $state.go(ref.state, params, options);});ui-sref最后調用的還是$state.go()方法
?
2 如何傳遞參數
?
首先,要在目標頁面定義接受的參數:
?
傳參,
ui-sref:
$state.go:
?
接收參數,
在目標頁面的controller里注入$stateParams,然后 "$stateParams.參數名" 獲取
轉載于:https://www.cnblogs.com/jager/p/5293225.html
總結
以上是生活随笔為你收集整理的在 Angularjs 中 ui-sref 和 $state.go 如何传递参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到三条小蛇是什么意思
- 下一篇: 女生梦到男生说明什么