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

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

问题描述

当我使用

Angular 添加了几个类,如 ng-validng-invalidng-dirtyng-pristine> 到允许显示有关验证结果的可视指示符的元素.

有没有办法在 Dart 代码中获得这些状态?

解决方案

好的,所以我刚刚查看了这个:

采用以下代码(形式和名称很重要!):

<表单名称="myForm"><input type='text' name="myInput" maxlength='25' required ng-model='ctrl.inputValue'></表单>

然后是以下指令/控制器/组件:

@NgController (选择器:[测试]",发布为:ctrl")类测试控制器{字符串输入值;范围thisScope;测试控制器(范围 this.thisScope){thisScope.$watch("ctrl.inputValue", () {NgModel inputModel = thisScope["myForm"]["myInput"];打印(输入模型.无效);});}}

这将输出模型是否有效.

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

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?

解决方案

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

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

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