Javascript 如何在AngularJS中调用控制器的初始函数?
我写了一些基于控制器的ui路由Javascript 如何在AngularJS中调用控制器的初始函数?,javascript,angularjs,controller,Javascript,Angularjs,Controller,我写了一些基于控制器的ui路由 $stateProvider .state('dashboard', { url: "/dashboard", views: { 'rightMainView' : { templateUrl: "dashboard/", controller: 'DashboardCtrl' } } })
$stateProvider
.state('dashboard', {
url: "/dashboard",
views: {
'rightMainView' : {
templateUrl: "dashboard/",
controller: 'DashboardCtrl'
}
}
})
.state('dashboard.all', {
url: "all/",
resolve: {
dashboards: ['dashboards', function(dashboards){
return dashboards.all();
}]
},
templateUrl: 'dashboard/all/',
controller: ['$scope', '$state', 'dashboards', DashboardAllCtrl]
})
;
...
function DashboardCtrl($scope, $state) {
$state.go('dashboard.all');
}
这段代码将在第一次工作。但是,如果我为dashboard单击相同的链接(重新调用dashboard/url),则不会调用$state.go函数
所以我只需要调用控制器的初始函数。如何实现这一点?您的“dashboard.all”状态设置在哪里?我添加了dashboard.all状态设置
templateUrl
的值应该是指向模板文件或ng模板(如“example.html”)的路径。并且始终检查浏览器控制台以查看发生了什么错误