0
我试图调试我的代码:我有我的简单服务“密码重置”在这里:AngularJs:xxx是不是一个函数,但工厂注入和函数中声明
(function() {
'use strict';
angular
.module('app.login')
.factory('ResetPasswordService', ResetPasswordService);
function ResetPasswordService($http, $q) {
function sendMessage() {
var there = this;
var deferred = $q.defer();
var data = {
email: this.email
};
$http({
method: 'POST',
url: 'password/email',
data: data
})
.then(_loginSuccess, _loginFailed);
function _loginSuccess(response) {
console.log(response);
deferred.resolve(there);
}
function _loginFailed(response) {
deferred.reject('Une erreur interne est survenue' + response.error);
}
return deferred.promise;
}
return sendMessage;
}
})();
而且我试图用它在我控制器,当用户点击“是”(事件的onTap - 确认密码重置)
(function() {
'use strict';
angular
.module('app.login')
.controller('LoginCtrl', LoginCtrl);
function LoginCtrl(UserModel, $ionicPopup, $scope, ResetPasswordService) {
var vm = this;
vm.user = UserModel.buildUser();
vm.login = login;
vm.forgotPassword = forgotPassword;
/**
* function called when user clicks on 'mot de passe oublié' button
* @function
* @name forgotPassword
* @memberOf App.Login.LoginCtrl
*/
function forgotPassword() {
vm.data = {
email : vm.user.email
};
var myPopup = $ionicPopup.show({
template: '<input type="email" ng-model="vm.data.email" placeholder="Entrez votre adresse email">',
title: 'Mot de passe oublié',
subTitle: 'Souhaitez vous réinitialiser' + ' <br> ' + 'votre mot de passe ?',
scope: $scope,
buttons: [
{text: 'Non'},
{
text: '<b>Oui</b>',
type: 'button-positive',
onTap: function (e) {
if (!vm.data.email) {
//don't allow the user to close unless he enters his email
e.preventDefault();
console.log('Le champs est vide ! ');
} else {
/!\ HERE /!\ ResetPasswordService.sendMessage() /!\ HERE /!\
.then(_success, _fail);
return vm.data.email;
}
}
}
]
});
myPopup.then(function (res) {
if (res) {
console.log('Tapped!', res);
}
else {
console.log('annulation');
}
});
}
}
})();
但后来我有一个消息,告诉我,
ResetPasswordService.sendMessage
不是功能。
但是,我已经注射了配套厂。我仍然是JS的新手,这不是我第一次看到这个消息,但我现在无法弄清楚......我又在做什么错了?
OOOOH所以这是它...你救我多一些时间ahaha。谢谢,我会记住我的错误!虐待标记为接受一旦我允许:) :) – DevMoutarde
@DevMoutarde很高兴它有点帮助!如果你能够upvote并且一旦允许,就会很棒。谢谢!当然是的,没有看到更新的评论:) – tanmay