AngularJS tan kufan zhi xing

ding yi he yong fa

AngularJS xiu gai <textarea> de mo ren xing wei ng-model cun zai

tong shi ting gai shen ze

tong shi ting gai shen ze required de <textarea> yu suan bei $valid zhuang tai jiu hui bei she zhi wei false

tong shi hai ting gai zhuang tai kong zhi

tan kufan zhi yuan you ddang dian zhuang tai

  • $untouched tan kufan wei shen me bei zhi chong
  • $touched tan kufan zai zhi chong
  • $pristine This field has not been modified
  • $dirty This field has been modified
  • $invalid Field content is invalid
  • $valid Field content is valid

mei ge zhuang tai de zhi yuan dai bao xian zhe yi ge boer zhi zhi, wei zhen hao huo jia

Example

dai you shu ju bao ding de tan kufan

<textarea ng-model="myTextarea"></textarea>
<p>tan kufan zhi yuan wei zhi shi:</p>
<h1>{{myTextarea}}</h1>

Try It Yourself

yu fa

<textarea ng-model="name"></textarea>

tong guo shi yong ng-model de zhi yuan wei yin zhuan xi tan kufan yu suan jian

CSS lei

AngularJS ying yong cheng xu nei <textarea> yu suan bei yu yin jian zai shen me zhuang tai xia she zhi ta de shi yi

tian jia le ddang dian lei

  • ng-untouched tan kufan wei shen me bei zhi chong
  • ng-touched tan kufan zai zhi chong
  • ng-pristine This field has not been modified
  • ng-dirty This field has been modified
  • ng-valid Field content is valid
  • ng-invalid Field content is invalid
  • ng-valid-key Validate each key every time. For example:ng-valid-requiredWhen there is more than one thing to validate, it is very useful.
  • ng-invalid-key For example:ng-invalid-required

If the value represented by the class is falseIf these classes are deleted.

Example

Use standard CSS to apply styles to valid and invalid text area elements:

<style>
textarea.ng-invalid {
    background-color: pink;
}
textarea.ng-valid {
    background-color: lightgreen;
}
</style>

Try It Yourself