2015-07-28 201 views
3

您好我有一個像電子郵件,標題,顏色一些輸入的形式...AngularJS如何禁用按鈕後點擊

我有2個按鈕「保存」和「撤消更改」。

我需要這個按鈕將永遠禁用接受,如果有什麼改變。 例如,我開始更改電子郵件,然後考慮。當我輸入新的電子郵件按鈕應該啓用,但點擊其中一個後,他們應該再次禁用。

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

如何在點擊其中一個按鈕後再次禁用它們?

回答

1

呼叫$scope.form.$setPristine()取消所有髒標誌:

function TodoCtrl($scope) { 

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

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

示例:http://jsfiddle.net/ej5et0f5/1/

1

只需創建,你會提交後,設置爲false變化的輸入信號後設置爲true的標誌變量,然後就去做:

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