我正在使用带有mongodb的节点js并使用js和angular作为前端来创建一个Web应用程序。问题是我添加了一个新的控制器来处理登录但似乎无论我做什么我都会得到同样的错误:
错误:[$ controller:ctrlreg]名为' userlogint'的控制器没有注册。
我实际上做了一些研究,我正在寻找答案,但没有什么可以帮助我使相同的代码适用于其他2个控制器,我真的没有想到为什么这个不能工作。我将粘贴我的代码:
这是我的app.js
var myApp = angular.module('myApp',['ngRoute']);
myApp.config(function($routeProvider){
$routeProvider.when('/',{
controller:'controllertipproduse',
templateUrl: 'views/Default.html'
})
.when('/produse',{
controller:'controllerproduse',
templateUrl: 'views/Produse.html'
})
.when('/login',{
controller:'userlogint',
templateUrl: 'views/Login.html'
})
.when('/produse/:tipp',{
controller:'controllerproduse',
templateUrl: 'views/CategorieProduse.html'
})
.when('/produse/detalii/:id',{
controller:'controllerproduse',
templateUrl: 'views/DetaliiProduse.html'
})
.when('/produsee/adaugareprodus',{
controller:'controllerproduse',
templateUrl: 'views/AdaugareProdus.html'
})
.when('/produse/editprodus/:id',{
controller:'controllerproduse',
templateUrl: 'views/EditareProduse.html'
})
.when('/despre',{
controller:'controllerproduse',
templateUrl: 'views/About.html'
})
.otherwise({
redirectTo : '/'
});
});
这是我的控制器文件userlogint.js
var myApp = angular.module('myApp');
myApp.controller('userlogint',
['$scope','$http','$location','routeParams',function
($scope,$http,$location,$routeParams){
$scope.Loginto = function(
$http.post('/api/login/',$scope.userr).then(succesCallback,errorCallback);
function succesCallback(response){
$scope.loginn = response.data;
window.location.href = '#/'
}
function errorCallback(error){
throw error;
}
)
}]);
当我在页面 http://localhost:3000/login 时会触发错误 我提到其他两个控制器具有相同的特定代码,就像这个一样,它们可以工作。