我正在尝试基于angular2dart构建表单。
组件类:
@Component(
selector: 'start-app',
directives: const[materialInputDirectives],
styleUrls: const ['login_component.css'],
templateUrl: 'login_component.html')
class LoginComponent {
String scaleImg = 'packages/wp_login/assets/scale.svg';
Login login = new Login();
onSubmit() {
print('Submit');
}
}
和模板:
<div class="container">
<div class="row">
<div class="image">
<img [src]="scaleImg">
</div>
<div class="forms">
<form (ngSubmit)="onSubmit()" #login="ngForm">
<div>
<material-input type="text" label="User" [(ngModel)]="login.user"></material-input>
</div>
<div>
<material-input type="password" label="Password" [(ngModel)]="login.password"></material-input>
</div>
<div>
<material-input type="text" label="Language" [(ngModel)]="login.language"></material-input>
</div>
<div>
</div>
</form>
</div>
</div>
</div>
我得到了错误:
我做错了什么?
答案 0 :(得分:3)
#login="ngForm"
创建一个引用login
指令的模板变量NgForm
。
[(ngModel)]="login.user"
失败,因为login
引用了#login="ngForm" template variable and the error message is right about that it doesn't have a property
用户。
您需要重命名模板变量或组件的属性。