I'm stuck with an issue when try to implement registering function for a web.
Honestly, i just read some document about angularJs (and little bit about javascript) yesterday + under push. So, do not so hard to me, please :)
Below is my directive:
var app = angular.module('register-user', []);
app.directive('register', function () {
return {
restrict: 'E',
templateUrl: 'app/views/register.html',
controller: RegistestCtrl,
controllerAs: 'registerCtrl'
};
});
The controller:
RegistestCtrl.$inject = ['RegisterService'];
function RegistestCtrl(registerService) {
this.user = {};
this.isProcessing = false;
this.isRegistering = function () {
return this.isProcessing;
};
this.setRegistering = function (value) {
this.isProcessing = value;
};
this.register = function () {
this.setRegistering(true);
function registerSuccess(result) {
alert("registerSuccess: " + JSON.stringify(result));
this.setRegistering(false);
}
function registerFail(error) {
alert(error.message)
this.setRegistering(false);
}
registerService.register(this.user.email, this.user.pass).then(registerSuccess, registerFail);
};
}
And here is the service in case:
angular.module('app').factory('RegisterService', RegisterService);
RegisterService.$inject = ['$http', 'ENDPOINT'];
function RegisterService($http, endpoint) {
var service = {};
service.register = register;
return service;
function register(email, pass) {
return $http({
method: 'POST',
url: endpoint.URL + endpoint.REGISTER,
data: {
"email": email,
"password": pass
}
}).then(handleSuccess, handleError);
}
function handleSuccess(res) {
return res.data;
}
function handleError(error) {
return function () {
return {
success: false,
message: error
};
};
}
}
Finally, the issues is:
TypeError: this.setRegistering is not a function at registerSuccess
It points to these lines:
this.setRegistering(false);
this.setRegistering(false);
Other thing is Ok, but i want to call this to hide the progress circle when finish register. Could you give me hint here.
I think something went wrong here with the scope of variable. But i don't know where to start.