angularjsangularjs-ng-show

Angularjs: ng-show not showing after set to true


<button type="button" class="btn btn-default" ng-click="callMe()"
    ng-show="isVisible">Call</button>

In my controller.js I tried to:

$scope.isVisible = false;
myService.callMe().success(function (response) {
    $scope.isVisible = true;
    alert("enabled");
}

But button "Call" is not showing (alert was shown). What went wrong? Thanks in advance.


Solution

  • You need to embed the service call inside the function,

    $scope.callMe = function(){
    myService.callMe().success(function (response) {
        $scope.isVisible = true;
        alert("enabled");
    }
    }
    

    I am not sure why you are using a service here, you can do without service as,

    $scope.callMe = function(){    
        $scope.isVisible = true;
        alert("enabled");     
    }
    

    WORKING DEMO