我ui.router
用来检测 Angular App 中的状态变化。但是控制器没有在加载时被调用。
下面是我的app.js
代码。
var admin = angular.module('admin',['admin.core']);
angular.module('admin.core', ['ui.router', 'satellizer', 'ngMaterial']);
admin.config(function($mdThemingProvider, $stateProvider,
$urlRouterProvider, $authProvider, $locationProvider){
$mdThemingProvider.theme('default').primaryPalette('light-blue', {
'default': '700',
'hue-1' : 'A200',
}).accentPalette('blue');
// Satellizer configuration that specifies which API route the JWT should be retrieved from
$authProvider.loginUrl = '/api/authenticate';
// Redirect to the auth state if any other states are requested other than users
$urlRouterProvider.otherwise('/admin/login');
console.log($stateProvider)
$stateProvider
.state('login', {
url: '/admin/login',
name: 'login',
controller: 'AuthController as auth',
})
.state('users', {
url: '/admin/users',
controller: 'UserController as user'
});
$locationProvider.html5Mode(true);
});
admin.controller('AuthController', AuthController);
function AuthController($auth, $state, $scope) {
console.log("Called");
var vm = this;
vm.login = function() {
var credentials = {
email: vm.email,
password: vm.password
}
console.log(credentials);
// Use Satellizer's $auth service to login
$auth.login(credentials).then(function(data) {
// If login is successful, redirect to the users state
$state.go('users', {});
});
}
}
AuthController
当我的状态是时不调用login
。