大佬教程收集整理的这篇文章主要介绍了AngularJS / ui-router:$ state.go在ng-click中不起作用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
根据https://github.com/angular-ui/ui-router/wiki/Quick-Reference#note-about-
using-state-within-a-template的定义,您可以将其添加到中$rootScope
,因此所有版本都可以使用范围和所有模板
angular.module("myApp").run(function ($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
});
我有以下代码的视图:
<input type="button" value="New Post" ng-click="$state.go('blog.new-post')">
目标是无需使用href即可过渡到新状态。不幸的是,上面的代码不会触发。
我还尝试为此视图在控制器中包括$ state:
app.controller('blogPostsController',function($scope,$stateParams,$http,$statE) ...
但是仍然没有。transictionTo也似乎不起作用。
有人对如何进行这项工作有任何想法吗?
编辑:我只能通过分配使其工作:
$scope.$state = $state;
在我的控制器内。这看起来很丑。如果没有将$ state分配给作用域,是否真的没有其他方法可以访问$ state?
以上是大佬教程为你收集整理的AngularJS / ui-router:$ state.go在ng-click中不起作用全部内容,希望文章能够帮你解决AngularJS / ui-router:$ state.go在ng-click中不起作用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。