当我使用时
<input type='text' maxlength='25' required ng-model='ctrl.inputValue'>
Angular 添加了几个类,例如 ng-valid
、ng-invalid
、ng-dirty
、ng-pristine
> 到允许显示有关验证结果的视觉指示器的元素。
是否有办法在 Dart 代码中获取这些状态?
最佳答案
好的,我刚刚查看了这个:
采用以下代码(形式和名称很重要!):
<div test>
<form name="myForm">
<input type='text' name="myInput" maxlength='25' required ng-model='ctrl.inputValue'>
</form>
</div>
然后是以下指令/ Controller /组件:
@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);
});
}
}
这将输出模型是否有效。
在此处查看 NgModel 的文档以了解其他字段: http://ci.angularjs.org/view/Dart/job/angular.dart-master/javadoc/angular.directive/NgModel.html
关于dart - 在 Dart 代码中获取 ng-model 验证状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21812728/