0
votes

I have a signup page that gets a response from the backend when the signup form is filled out and the signup button is pressed.

If the username exists within the database, the response returns false, and then from there I change a $scope variable ($scope.signedUp) to true, which should simply show this existing error message:

<div class="padding assertive" ng-show="signedUp">
   <i class="icon ion-minus-circled"></i>
   Woops! Looks like that user already exists, try a different username.
</div>

Here is the current scope function within the signup controller:

$scope.signup = function(){
   User.signup($scope.credentials).then(function(res){
      if(res === false){
         console.log('res is: ', res);
         $scope.signedUp = true;
         console.log('$scope.signedUp ',$scope.signedUp);
      }
   });
};

The first time I fill the information out, and click signup, the console logs log this:

app.js:47 res is:  false 
app.js:49 $scope.signedUp  true

However, the error does not show up, oddly however, when I click it again, it does show up, yet nothing in the console log differs, Is this a bug with ionic? I noticed a similar post here:

ng-hide/ng-show within an ng-hide/ng-show not working properly in **chrome** on first trigger, second time it reflects just fine

But it seems the poster worked around it with display none, I would not like to do this if possible, thank you.

1
I was wondering if the answer below answered your question if not is there anything else you need to know? Standard practice would to be 'accept' an answer below if this resolves your question. - Parsa

1 Answers

1
votes

If you update a variable in the scope which is visible in the view run the following line:

$scope.$apply();

This flushes output and the view will update. However it is hard to say without seeing your full code.