angularjs ng-show 运行不正常

angularjs ng-show not working perfectly

我想用 ng-show 指令显示和隐藏按钮。

这是我的 HTML 文件:

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

这是我的 controllerScript 文件:

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

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

我想你在 HTML 中忘记了 ng-appng-controller。应该是:

<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>

控制器:

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

我有关于 Show/Hide Edit Button 的演示,来自您的代码:Here!

检查这个 Plnkr:http://plnkr.co/edit/veAeGPtYQIq9IQlBc1Ob?p=preview

您似乎忘记了在单击编辑按钮时更改 $scope.editBtn 的状态。在控制器中,函数editEmployee,你必须添加:

$scope.editBtn=true;

另外,我添加了变量 saveBtn 以在用户编辑时隐藏。并添加了一个取消按钮。您可以在 plnkr 中检查这 3 个元素。