這裏是我的controller
Can Angular Service可以在調用服務的Controller中調用一個函數嗎?
RegisterController.$inject = ['$location', '$scope', 'Authentication'];
function RegisterController($location, $scope, Authentication){
var vm = this;
vm.register = register;
function register(){
Authentication.register(vm.email, vm.password, vm.confirm_password, vm.username);
}
function register_error_display(error_list){
console.log("what is going on")
}
}
這裏是我的service
function Authentication($cookies, $http, RegisterController){
var Authentication = {
register: register
};
return Authentication;
// Register logic
function register(email, password, confirm_password, username){
return $http.post('/api/v1/accounts/',{
username: username,
password: password,
confirm_password: confirm_password,
email: email
}).then(registerSuccess, registerError);
}
function registerError(response){
error_list = response["data"];
RegisterController.register_error_display(error_list);
}
}
流程是這樣的register (controller)
- >post (service)
- >registerError (service)
- >register_error_display (controller)
我相信這正在給我返回這個錯誤
Error: [$injector:unpr] Unknown provider: RegisterControllerProvider <- RegisterController <- Authentication
什麼是這個錯誤的原因,是有辦法解決它?
錯誤很明顯:你試圖注入未知服務,沒有服務'RegisterController'(它不是服務)。 – dfsq
是否有可能將控制器注入服務?如果我想在服務器中的控制器中使用某個功能,有什麼替代方案? – Kevin