简体   繁体   English

使用AngularJS禁用按钮时,如何更改按钮的文本?

[英]How can I change the text of a button when it is disabled using AngularJS?

I have a SAVE button that is disabled when a form is pristine. 我有一个“保存”按钮,当表单原始时,该按钮被禁用。 I want it to say SAVED when pristine and then change to SAVE when the form is dirty. 我希望它在原始时说“保存”,然后在表格变脏时改为“保存”。 Working fine except the text change for the button. 除了按钮的文本更改外,其他都工作正常。 Here is the code: 这是代码:

     <input type="button" value="SAVED" class="button success radius expand" ng-click="save(form)" ng-disabled="!signupform.$dirty" ng-class="{disabled:!signupform.$dirty}">

If you want to make inline just do: 如果要进行内联,请执行以下操作:

<input type="button" value="{{(signupform.$dirty)? 'save' : 'saved'}}" class="button success radius expand" ng-click="save(form)" ng-disabled="!signupform.$dirty" ng-class="{disabled:!signupform.$dirty}">

You can also create a function in your controller to return the text. 您还可以在控制器中创建一个函数以返回文本。 This can be useful if your logic is larger (different texts for various specific cases). 如果您的逻辑较大(针对各种特定情况的不同文本),这将很有用。

html HTML

     <input type="button" value="{{getInputText()}}" class="button success radius expand" ng-click="save(form)" ng-disabled="!signupform.$dirty" ng-class="{disabled:!signupform.$dirty}">

controller : 控制器

function getInputText(form) {
    return (form.$dirty)? 'save' : 'saved';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM