0

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).

3 Answers 3

1

Use $scope.$apply()

$scope.$apply(function() {
   $reg.loading = false;
});
Sign up to request clarification or add additional context in comments.

Comments

1

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;
    });
};

Comments

0

Try changing scope to rootScope.

2 Comments

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
I did try to answer what was asked here. I don't have reputation otherwise would have commented. And please don't ever discourage someone who is new to something. @cartant

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.