Angularjs 为什么这个有角度的ui路由器代码会在$digest中导致无限循环?
我已经尽我所能把代码写下来了。有关嵌套状态和事件处理/广播的某些信息正在导致无限循环。在Chrome中,我可以暂停它,并看到它在Angular的Angularjs 为什么这个有角度的ui路由器代码会在$digest中导致无限循环?,angularjs,angular-ui-router,Angularjs,Angular Ui Router,我已经尽我所能把代码写下来了。有关嵌套状态和事件处理/广播的某些信息正在导致无限循环。在Chrome中,我可以暂停它,并看到它在Angular的$digest函数中永远循环。知道为什么吗?它是我的示例代码中的一个bug,还是 angular.module('bugapp',['ui.router'])) .run(函数($rootScope、$state、$stateparms){ $rootScope.$state=$state; $rootScope.$stateParams=$state
$digest
函数中永远循环。知道为什么吗?它是我的示例代码中的一个bug,还是
angular.module('bugapp',['ui.router']))
.run(函数($rootScope、$state、$stateparms){
$rootScope.$state=$state;
$rootScope.$stateParams=$stateParams;
})
.config(函数($locationProvider、$stateProvider、$urlRouterProvider){
$locationProvider.html5Mode(false);
$stateProvider
.state(“根”{
摘要:没错,
url:“/servletContext?asUser”,
模板:“”/???
})
.state(“root.home”{
摘要:没错,
网址:“/home”,
模板:“”
})
.state(“root.home.profile”{
url:“/profile”,
模板:“随便什么”
})
})
.controller('BugAppCtrl',函数($scope、$state、$stateparms、$log、$location){
$log.log('BugAppCtrl:constructor');
$scope.hasData=函数(){
var res=!!$scope.foo;
//$log.log(“hasdatacalled,returing”+res+“foo是”+$scope.foo);
返回res;
};
$scope.$on(“$stateChangeSuccess”,函数(){
$log.log(“状态已更改!(改为“+$State.current.name+”);
$scope.foo=‘垃圾’;
$scope.$broadcast(“resetfoo”);
});
$state.go('root.home.profile');
});
我怀疑这是UI路由器中的一个错误,原因有两个:
$location.path('/servletContext/home/profile');
url: "/profile/:foo",
然后在$location.path调用中,在路径中添加参数:
$location.path('/servletContext/home/profile/12');
您可以从访问控制器中的12
$stateParams.foo
这很有帮助。当您使用$location而不是$state时,您是否以这种方式成功地转换到具有参数的状态?看起来是可能的-我尝试过并在回答中添加了信息。对我来说,位置路径也是一样,我发出一些事件事件,至少让UI路由器构造您将要更改的位置更可取,aka:
$location.path($state.href('my.state.name',{foo:'bar');
$stateParams.foo