matth3o matth3o - 2 months ago 20
Dart Question

dart angular2 - form directive #mymodel="ngForm" not working

When I put in my template something like

<input id="password" name="password" class="form-control" type="password" [(ngModel)]="password" ngControl="password" #password="ngForm" required minlength="6" maxlength="30">


I cannot start my application, I have the following message :

Can't read 'package:website/login_component.template.dart' (Could not find asset website|lib/login_component.template.dart.).
import 'package:website/login_component.template.dart' as i2;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Warning from Dart2JS on atthecorner_website|web/main.dart]:
web/main.template.dart:33:1:
'i2' has no member named 'initReflector'.
i2.initReflector();
^^^^^^^^^^^^^^^^^^


If I remove the attribute
#password="ngForm"
it works.

My pubspec.yml :

name: website
description: website
version: 0.0.1
environment:
sdk: ">=1.13.0 <2.0.0"
dependencies:
angular2: 2.0.0-beta.20
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:
- angular2:
platform_directives:
- 'package:angular2/common.dart#COMMON_DIRECTIVES'
- 'package:angular2/common.dart#FORM_DIRECTIVES'
platform_pipes:
- 'package:angular2/common.dart#COMMON_PIPES'
entry_points: web/main.dart
- dart_to_js_script_rewriter


I looked at this repo (https://github.com/angular-examples/forms) which works fine, but I cannot see any differences.

Thanks for your help !

Answer

I found it!

The tag #property="ngForm" only works if the property is wrapped into a bean acting as the model. If the property is just in the component, it doesn't work.