Get ng-model validation status in Dart code

早过忘川 提交于 2019-12-18 09:26:03

问题


When I use

<input type='text' maxlength='25' required ng-model='ctrl.inputValue'>

Angular adds several classes like ng-valid, ng-invalid, ng-dirty, ng-pristine to the element that allow showing visual indicators about the validation result.

Is there a way to these status in Dart code?


回答1:


Okay so I have just looked in to this:

Take the following code (Form and names are important!):

<div test>
    <form name="myForm">
         <input type='text' name="myInput" maxlength='25' required ng-model='ctrl.inputValue'>
    </form>
</div>

Then the following directive/controller/component:

@NgController (
selector: "[test]",
publishAs: "ctrl"
)
class TestController {
  String inputValue;
  Scope thisScope;
  TestController (Scope this.thisScope) {
    thisScope.$watch("ctrl.inputValue", () { 
      NgModel inputModel = thisScope["myForm"]["myInput"];
      print(inputModel.invalid);
    });
  }
}

This will output whether the model is valid or not.

View documentation for NgModel here for other fields: http://ci.angularjs.org/view/Dart/job/angular.dart-master/javadoc/angular.directive/NgModel.html



来源:https://stackoverflow.com/questions/21812728/get-ng-model-validation-status-in-dart-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!