在 Angularjs 中 ui-sref 和 $state.go 如何传递参数
来源:互联网 发布:汉诺塔递归算法机制 编辑:程序博客网 时间:2024/06/17 00:47
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. 如何传递参数
首先,要在目标页面定义接受的参数:
.state("message-list",{ templateUrl:"templates/message-list.html", controller:"MessageCtrl"}).state("message-detail",{ params:{"messageId":null}, templateUrl:"tmmplates/message-detail.html", controller:"MessageDetailCtrl"})
然后,传递参数,
ui-sref:
<ion-content style="background-color:#F0F0F0;"> <div class="list"> <a class="item item-thumbnail-left" ng-repeat="itme in items" ui-sref="message-detail({{messageId:item.messageID}})"></a> <img src="img/msg.jpg"> <h2 ng-bind="item.messageTitle"></h2> <p ng-bind="item.messageContent"></p> <p ng-bind="item.lastModifyTime"></p> </div></ion-content>
$state.go:
.controller("firstCtrl",function($scope,$state){ $state.go("login",{test:333});});
最后,接收参数
在目标页面的controller里注入 $stateParams ,然后 “$stateParams.参数名” 获取
.controller("MessageDetailCtrl",function($scope,$http,$stateParams,$ionicLoading){ //console.log($stateParams.messageId);});
阅读全文
0 0
- 在 Angularjs 中 ui-sref 和 $state.go 如何传递参数
- 在 Angularjs 中 ui-sref 和 $state.go 如何传递参数
- 在 Angularjs 中 ui-sref 和 $state.go 如何传递参数
- 在 Angularjs 中 ui-sref 和 $state.go 如何传递参数
- 在 Angularjs 中 ui-sref 和 $state.go 如何传递参数
- 在 Angularjs 中 ui-sref 和 $state.go 如何传递参数
- 在 Angularjs 中 ui-sref 和 $state.go 如何传递参数
- 在 Angularjs 中 ui-sref 和 $state.go 如何传递单个多个参数和将对象作为参数
- Angularjs 中 ui-sref 和 $state.go 如何传递单个多个参数和将对象作为参数
- angularjs中,ui-sref传递参数
- ui-sref如何传递参数
- angularjs中ui-sref传值步骤
- $state.go 传递参数
- $state.go跳转中 传递对象参数
- 【ionic+angularjs】angularjs ui-router路由简介($urlRouter、$state、$stateProvider、ui-sref....)
- AngularJS开发WebApp高亮跳转按钮效果,ui-sref和ui-sref-active的使用
- ionic $state.go 传递参数
- $state.go页面传递参数
- 知乎用户分布研究
- 线程的两种创建及线程池——学习二
- Floyd 算法 和 非递归算法寻路
- 在Ubuntu中使用apt-get的时候,始终显示“E:无法定位软件包”,E: 无法获得锁 /var/lib/apt/lists/lock
- 用Crt系列函数分析windows程序的内存泄露
- 在 Angularjs 中 ui-sref 和 $state.go 如何传递参数
- hbase的createTable
- LeetCode 66.Plus One
- python学习之——模块(import + from * import *)
- Android kswapd-->lowmemorykiller启动和扫描过程
- 网络编程的5个IO模型
- eclipse小技巧
- 新版APP提交AppStore前要检查的iOS配置代码和Xcode Build Settings等相关配置条目(CheckList Before Submit AppStore)
- 版本质量控制指标