感谢SO社区的一些帮助,我有一个工作角度SPA,它使用
ui-router库使用多个状态/视图.但是我得到的行为似乎与angular-ui-router文档不一致.
从他们关于onEnter的文档中,我希望无论何时我使用$state.go(“home”),与该状态的配置对象相关的onEnter()事件都会启动,但我不认为它会发生.例:
/* myApp module */ var myApp = angular.module('myApp',['ui.router']) .config(['$stateProvider',function ($stateProvider) { $stateProvider.state('home',{ url: "/",views: { 'top': { url: "",template: '<div>top! {{topmsg}}</div>',controller: function ($scope) { $scope.topmsg = "loaded top!"; console.log("top ctrl!"); },onEnter: function () { console.log("entered bottom state's onEnter function"); } },'middle': { url: "",template: '<div>middle! {{middlemsg}}</div>',controller: function ($scope) { $scope.middlemsg = "loaded middle!"; console.log("middle ctrl!"); },'bottom': { url: "",template: '<div>bottom! {{bottommsg}}</div>',controller: function ($scope) { $scope.bottommsg = "loaded bottom!"; console.log("bottom ctrl!"); },onEnter: function () { console.log("entered bottom state's onEnter function"); } } },onEnter: function () { console.log("entered home state"); } }); }]) .controller('MyAppCtrl',function ($scope,$state/*,$stateParams*/) { $scope.statename = $state.current.name; $scope.testmsg = "app scope working!"; console.log("MyAppCtrl initialized!"); $state.go("home"); });
正如你可以从状态的配置对象中的所有onEnter()调用中看到的那样,我的期望是当家庭状态加载时,我会开始看到他们正在触发控制台消息的所有状态/视图的列表.但是,仅从主状态的onEnter事件中记录第一个输入的本地状态消息.没有一个其他视图的onEnter被击中.我误读了文档吗?
Here is a long-awaited fiddle进行演示.只需在firebug / chrome devtools中显示控制台,您就会看到缺少控制台输出.
任何帮助都会很棒.我正在使用角度1.2和ui-router 0.2.0.提前致谢!