Nicolas Girardin
Nicolas Girardin

Reputation: 607

How to manipulate forms in Angular Dart?

I'm can't find any doc that explains how to manipulates forms in Angular Dart.

I've got 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 following one 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);
  }

}

The validation works well, but when clicking on the button, the print(form) statement always prints null.

Any idea?

Thanks

Upvotes: 4

Views: 1092

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 658067

I guess 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);
  }
}

Upvotes: 1

Related Questions