问题
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