消息中心$state.go('someState')一般使用在 controller里面;.controller('firstCtrl', function($scope, $state) { $state.go('login'" />

详解在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.参数名" 获取

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

tag:传递参数详解电脑软件angularjssref

相关内容