Get ng-model validation status in Dart code

前端 未结 1 1478
夕颜
夕颜 2020-12-21 15:29

When I use


A

相关标签:
1条回答
  • 2020-12-21 16:15

    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

    0 讨论(0)
提交回复
热议问题