Я перемещаюсь с Углового 1.4.8 на 1.6.1 при подготовке к переходу на Угловое 2. Я слежу за шагами множественного возраста Джо Эйма для перехода на последнюю версию угловые 1 (1.5+) до перехода на угловую 2. Я, кажется, сделал Everthing правильно, но я получаю сообщение об ошибке,Контроллер, не зарегистрированный после перехода на Угловой 1.6.1 Компонент
[$ контроллер: ctrlreg] контроллер с именем «Userlogin» не зарегистрирован.
Я проверил другие столбцы переполнения стека. Один показывает позицию ссылки на контроллер в файле сценариев, поэтому я переместил ссылку на скрипт userLogin и проблема осталась. Я включил код компонента и раздел маршрутизации, который относится к userLogin. Обратите внимание, что я использую ui-router, который может вызвать проблему, но не знаю, почему. Оцените любые предложения о том, что я могу делать неправильно.
userLogin.js
(function() {
'use strict';
var app = angular.module('app',[]);
angular.module('app').component('userLogin',{
templateURL: '/account/userLogin.html',
bindings: {
},
controller: function userLogin($http, flIdentity, flNotifier,flAuth, $state, flConstructQueryParameterService) {
this.identity = flIdentity;
//Take out both lines after testing - Do not even leave the variables
this.username = "[email protected]";
this.password = "joe";
this.signin = function (username, password) {
flAuth.authenticateUser(username, password).then(function (success) {
if (success) {
flConstructQueryParameterService.setOwnerId(flIdentity.currentUser._id);
flNotifier.notify('You have successfully signed in!');
console.log("login - successful signin see if currentUser is defined " + flIdentity.currentUser);
} else {
flNotifier.notify('Username/Password combination incorrect');
}
});
$state.go('home');
}
this.signout = function() {
console.log('Signing User Out ');
flAuth.logoutUser().then(function() {
this.username = "";
this.password = "";
flNotifier.notify('You have successfully signed out!');
$state.go('home');
})
};
this.loadReferenceData = function() {
console.log('Loading Reference Data ');
$http.post("/loadReferenceData")
.then(
function (response) {
// success callback
},
function (response) {
// failure callback
}
);
};
this.signUp = function() {
console.log("login - SignUp function");
//$modalInstance.close();
$state.go('signup');
}
}
});
})();
--------------------------------------------------
app.js
.state('login', {
url: '/login',
views: {
'content-header': {
templateUrl: '/app/main/main-header',
controller: 'flMainCtrl',
caseInsensitiveMatch: true
},
'content-banner': {
templateUrl: '/app/main/main-carousel',
controller: 'flMainCtrl',
caseInsensitiveMatch: true
},
'content-main': {
template: '<user-login></user-login>',
//controller: 'login',
caseInsensitiveMatch: true
},
'content-left': {
templateUrl: '/app/main/main-menu-left',
controller: 'flMainCtrl',
caseInsensitiveMatch: true
},
'content-right': {
templateUrl: '/app/main/main-menu-right',
controller: 'flMainCtrl',
caseInsensitiveMatch: true
},
'content-footer': {
templateUrl: '/app/main/main-footer',
controller: 'flMainCtrl',
caseInsensitiveMatch: true
}
}
})
Создать [mcve] demo в plunker, который воспроизводит проблему – charlietfl
попробуйте изменить 'controller: function userLogin (' to 'controller: function ('. – charlietfl
Сообщение об ошибке было вызвано использованием одного и того же контроллера с несколькими шаблонами. Я исправил это, но у меня все еще есть Проблема: я нахожу, что UI-маршрутизатор немного пригоден при использовании компонентов. Мой маршрутизатор UI включает в себя несколько маршрутов и каждый вид маршрута 6. Сначала я пытался просто сменить один контроллер r (т.е. один маршрут, один вид). Этот один компонент/шаблон не отображался. Я изменил все виды маршрута на компоненты, и теперь шаблоны не отображаются. Теперь я собираюсь сократить до 2 маршрутов и использовать только компоненты, без контроллеров, для всех видов. Идеи или подобные переживания? –