如何在点击时禁用一个按钮,并使用AngularJS将该按钮替换为另一个具有不同功能的按钮

How to disable a button on click and replace that button with another button with different function using AngularJS?

本文关键字:按钮 替换 AngularJS 另一个 功能 一个      更新时间:2023-09-26

如何在点击时禁用一个按钮,并使用AngularJS将该按钮替换为另一个具有不同功能的按钮?下面是我的按钮,

<button type="submit" class="btn btn-small btn-default"
ng-disabled="isteam==0 || secondEdit" ng-click="editSetting()">
<span class="glyphicon glyphicon-edit"></span>&nbsp;Edit Setting</button>

您可以使用状态设置,比如$scope.showFirstButton=true来控制何时显示提交按钮:

<button ng-show="showFirstButton" type="submit" class="btn btn-small btn-default" ng-disabled="isteam==0 || secondEdit" ng-click="editSetting()">Edit Setting</button>

和另一个按钮,交替显示它们:

<button ng-show="!showFirstButton" type="submit" class="btn btn-small btn-default" ng-click="doSomethingElse()">Seccond Button</button>

在控制器方法$scope.editSetting()中,可以更改状态的值:$scope.showFirstButton = !$scope.showFirstButton'

编辑:如果您需要恢复按钮的状态,请在第二种方法中执行相同的操作:

$scope.doSomethingElse = function(){
  //some cool things happen here, and:
  $scope.showFirstButton = !$scope.showFirstButton
}

这将收回第一个按钮并隐藏第二个按钮。