在Dart代码中获取ng-model验证状态 [英] Get ng-model validation status in Dart code

查看:141
本文介绍了在Dart代码中获取ng-model验证状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用

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

Angular添加了 ng-valid ng-invalid ng-dirty ng-pristine

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.

在Dart代码中是否有这些状态的方法?

Is there a way to these status in Dart code?

推荐答案

好的,所以我刚刚看过这个:

Okay so I have just looked in to this:

!):

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

然后下面的指令/ controller / component:

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.

查看NgModel的其他文档:
http://ci.angularjs.org/view/Dart/job/angular.dart-master/javadoc/angular.directive/NgModel .html

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

这篇关于在Dart代码中获取ng-model验证状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆