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屋!
查看全文