Call In my controller.js I tried to: $scope.isVisible =" /> Call In my controller.js I tried to: $scope.isVisible =" /> Call In my controller.js I tried to: $scope.isVisible ="/>

Angularjs: ng-show not showing after set to true

55 Views Asked by At
<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.

1

There are 1 best solutions below

9
Sajeetharan On BEST ANSWER

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