AngularJS单击后如何禁用按钮

AngularJS单击后如何禁用按钮,angularjs,Angularjs,嗨,我有一个表格,里面有一些输入,比如电子邮件,标题,颜色 我有两个按钮“保存”和“撤消更改” 我需要这个按钮将始终被禁用接受,如果有什么改变。 例如,我开始改变电子邮件,然后我考虑。当我键入新的电子邮件按钮时,应该启用,但在单击其中一个按钮后,应该再次禁用它们 <form name="form" ng-submit="change()" novalidate> <input type="text" ng-model="title"/> <input

嗨,我有一个表格,里面有一些输入,比如电子邮件,标题,颜色

我有两个按钮“保存”和“撤消更改”

我需要这个按钮将始终被禁用接受,如果有什么改变。 例如,我开始改变电子邮件,然后我考虑。当我键入新的电子邮件按钮时,应该启用,但在单击其中一个按钮后,应该再次禁用它们

<form name="form" ng-submit="change()" novalidate>
    <input type="text" ng-model="title"/>
    <input type="email" name="email" ng-model="email" placeholder="{{email}}" />
    <input type="color" ng-model="color"/>

    <button type="submit" ng-disabled="!form.$dirty">SAVE</button>
    <a ng-click="cancel()" ng-disabled="!form.$dirty">UNDO CHANGES</a>
</form>

拯救
撤消更改

单击其中一个按钮后,如何使其再次禁用?

只需创建一个标志变量,提交后设置为true,更改输入后设置为false,然后执行以下操作:

<button type="submit" ng-disabled="flagVariable">

调用
$scope.form.$setPristine()
取消所有脏标志:

function TodoCtrl($scope) {

    $scope.change = function() {
        $scope.form.$setPristine();
    }

    $scope.cancel = function() {
        $scope.form.$setPristine();
    }
}
例如: