angularjs app.run不会被带状态调用 [英] angularjs app.run doesn't get called with state
本文介绍了angularjs app.run不会被带状态调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我根本看不到问题,这是我的代码.
I can't see the problem at all, here's my code.
var app = angular.module('application', ['ui.router', 'ngResource','user.controllers','user.services']);
app.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('home', {
url: '',
templateUrl: 'views/home.html'
}).state('account', {
url: '/account',
templateUrl: 'views/user/account.html',
controller: 'UserCtrl'
}).state('login', {
url: '/login',
templateUrl: 'views/user/login.html',
controller: 'UserCtrl'
}).state('logout', {
url: '/logout',
templateUrl: 'views/user/logout.html',
controller: 'UserCtrl'
}).state('register', {
url: '/register',
templateUrl: 'views/user/register.html',
controller: 'UserCtrl'
});
});
app.run(function ($rootScope, $state) {
$rootScope.$on("$stateChangeStart", function (event, toState, toParams, fromState, fromParams) {
console.log('toState.name: ' + toState.name);
console.log('fromState.name: ' + fromState.name)
});
});
这似乎很简单,但是却行不通.我确信这对Angular来说我是一点都不了解,所以任何帮助都将不胜感激.
It seems pretty straightforward to do, but it just doesn't work. I'm sure it's a little thing I don't know about Angular, so any help would be appreciated.
谢谢!
推荐答案
在发布的代码中,您似乎在$stateProvider.state
声明的末尾缺少结尾的})
.
In the code you posted, it looks like you're missing a closing })
at the end of your $stateProvider.state
declaration.
更新:
这篇关于angularjs app.run不会被带状态调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文