在 Dart 代码中获取 ng-model 验证状态 [英] Get ng-model validation status in Dart code
问题描述
当我使用
Angular 添加了几个类,如 ng-valid
、ng-invalid
、ng-dirty
、ng-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屋!