ng-show not updating the view

3.9k views Asked by At

ng-show="my.message" is set to true in http success but it doesn't update the view.

Here is my code:

Controller Js:

  lgControllers.controller('FormCtrl', function($scope, $http) {

                $scope.my = {
                    message: false
                };
                $scope.submitForm = function() {                       

                    $http({
                        url: "../saket/ajax.php",
                        data: "email_id=" + $scope.form.emailaddress + "&category_id=" + cat_num + "&action=subscribe",
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                        }
                    }).success(function(data) {

                            $scope.my = {
                                message: true
                            };

                        console.log(data); // http is success
                        console.log($scope.my.message); // gives true

                    }).error(function(err) {
                        "ERR", console.log(err)
                    })
                };

            });

Index.html:

    <div ng-controller="FormCtrl">
        <div ng-show="my.message">It worked!</div>
    </div>

my.message gives true in console but the div remains hidden in the view.

I can't figure out where the problem is.

1

There are 1 answers

2
eesdil On

Can it be that you are overwriting the message property, and angularjs is loosing the reference?

$scope.my = {
    message: true
;

try just :

$scope.my.message = true;