Semah Mhamdi Semah Mhamdi - 6 months ago 76
AngularJS Question

angularjs ng-show not working perfectly

I want to show and hide a button with ng-show directive.

Here is my HTML file:

<button class="btn btn-info" ng-show="editBtn">Save Edit
<span class="glyphicon glyphicon-ok"></span>
</button>


Here is my controllerScript file:

myApp = angular.module("myApp", []);

myApp.controller ("epmloyeeCtrl", ["$scope", function($scope){
$scope.editBtn = false;
}]);

Answer

I think your forgot ng-app or ng-controller in HTML. It should be:

<div ng-app="myApp">
   <div ng-controller="epmloyeeCtrl">
     <button class="btn btn-info" ng-show="editBtn">Save Edit
        <span class="glyphicon glyphicon-ok"></span>
      </button>
   </div>
</div>

Controller:

var myApp = angular.module("myApp", []);
myApp.controller ("epmloyeeCtrl", ["$scope", function($scope){
  $scope.editBtn = false;
}]);

I have demo about Show/Hide Edit Button from your code: Here!

Comments