Reputation: 310
I am trying to create a controller function to submit a signup with firebase, but it seems that the variables from the scope (controllerAs: $reg
) are not binding when they are updated inside the promise.
When $reg.loading
is changed to true, it is correctly updated in the template, but when is changed to false, the scope variable is updated in the controller but the template ignores it.
$reg.submit = () => {
$reg.loading = true;
firebase.auth().createUserWithEmailAndPassword($reg.user.email, $reg.user.password)
.catch(error => {
$reg.loading = false;
});
};
The template is just a form where I call $reg.submit()
function when the submit button is clicked (tested with both ng-submit & ng-click).
Upvotes: 0
Views: 132
Reputation: 310
Finally found my error.
I was using firebase
common object, which is not aware about I am using Angular, what I should use is the object $firebaseAuth
(injected on the controller) from AngularFire library.
This way I have a promise worried about doing itself the $digest loop in Angular:
$reg.submit = () => {
$reg.loading = true;
$firebaseAuth.$createUserWithEmailAndPassword($reg.user.email, $reg.user.password)
.catch(error => {
$reg.loading = false;
});
};
Upvotes: 1
Reputation: 17721
Use $scope.$apply()
$scope.$apply(function() {
$reg.loading = false;
});
Upvotes: 1