How to manipulate forms in Angular Dart?

I cannot find any document that explains how to manipulate forms in Angular Dart.

I have the following code in my_component.html:

<form name="form" ng-submit="comp.save()">
  <input type="text" required ng-model="comp.user.firstname">
  <input type="text" required ng-model="comp.user.lastname">
  <button ng-disabled="form.invalid">Save</button>
</form>

And the next one is in my_component.dart:

@NgComponent(
  selector    : 'my-component',
  templateUrl : 'my_component.html',
  publishAs   : 'comp'
)
class MyComponent {

  @NgTwoWay('user')
  User user;

  @NgTwoWay('form')
  NgForm form;

  MyComponent() {};

  void save() {
    print(form);
  }

}

Validation works well, but when the button is pressed, the operator print(form)always prints null.

Any idea?

thank

+4
source share
1 answer

I think this is what you want:

class MyComponent {
  @NgTwoWay('user')
  User user = new User();

  Scope scope;

  MyComponent(this.scope) {}

  void save() {
    var form = (scope.context['form'] as NgForm);
    print(form.invalid);
  }
}
+1
source

Source: https://habr.com/ru/post/1531962/


All Articles