我正尝试学习Angular2dart,并遵循Angular2dart网站上的教程。
考虑以下代码:
import 'package:angular2/core.dart';
class Hero {
final int id;
String name;
Hero(this.id, this.name);
}
@Component(
selector: 'my-app',
template: '''
<h1>{{title}}</h1>
<h2>{{hero.name}} details!</h2>
<div><label>id: </label>{{hero.id}}</div>
<div>
<label>name: </label>
<input [(ngModel)]="hero.name" placeholder="name">
</div>'''
)
class AppComponent {
String title = 'Tour of Heroes';
Hero hero = new Hero(1, 'Windstorm');
}
当我编译时,它显示了错误信息:
Build error:
Transform TemplateCompiler on Sample|lib/app_component.ng_meta.json threw error: Template parse errors:
Can't bind to 'ngModel' since it isn't a known native property or known directive. Please fix typo or add to directives list. ("
<div>
<label>name: </label>
<input [ERROR ->][(ngModel)]="hero.name" placeholder="name">
</div>"): AppComponent@5:15
我做错了什么?
import { FormsModule } from '@angular/forms';
。在Dart中也应该有类似的东西。否则,如果你将它添加到组件的顶部,它也会起作用。 - Deblaton Jean-Philippe