4

I am building a simple web page signup form in Angular storing the data in Parse.

controller('AppCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {

    $rootScope.groupCreated = false;

    $scope.signUp = function(form) {

        var Group = Parse.Object.extend("AdminOrg");
        var group = new Group();
        group.set("groupName", form.name);
        group.set("groupPassword", form.password);

            group.save(null, {
                  success: function(data) {
                      $rootScope.groupCreated = true;

                  },
                  error: function(data, error) {
                    alert(error.message);
                  }
                });
      };
}]);

I am using $rootScope.groupCreated in my HTML to hide the signup form and show a "Group successfully created" message once the success function is called. The value is successfully being changed to true but it's not changing the html view. I am using the following to hide and show two divs:

ng-hide="$rootScope.groupCreated"
ng-show="$rootScope.groupCreated"

Am I accessing the $rootScope incorrectly in my HTML?

3
  • 1
    Just ng-hide="groupCreated" should be used Commented Nov 14, 2015 at 19:19
  • @vp_arth good catch. Commented Nov 14, 2015 at 19:22
  • Awesome, thanks for that. Commented Nov 14, 2015 at 20:37

1 Answer 1

5

Well Angular just doesn't know that you've changed something on the scope, because Parse functions are not part of Angular ecosystem, so not included into digest check loops. Just let Angular know manually with $apply method:

group.save(null, {
    success: function (data) {
        $rootScope.groupCreated = true;
        $rootScope.$apply();
    },
    error: function (data, error) {
        alert(error.message);
    }
});

And another problem, thanks to vp_arth for noticing in comments: you don't use $rootScope prefix in Agnular expressions:

ng-show="groupCreated"
Sign up to request clarification or add additional context in comments.

Comments

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.