ui.router
을 사용하여 각도 앱의 상태 변화를 감지했습니다. 그러나 컨트롤러가로드시 호출되지 않습니다.ui.router 상태가 예상대로 작동하지 않습니다.
아래 코드는 내 app.js
코드입니다. 내 상태가 login
때
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
가 호출되지 않습니다.
왜 '사용자'가 아닌 '사용자'입니까? 그리고 이름을 추가하십시오 : 'users' –
@ PiotrPęczek .. – Gags
당신은 루트 앱 html 어딘가에'ui-view'를 가지고 있습니까? – devqon