【发布时间】:2018-01-10 18:14:33
【问题描述】:
考虑到下面的代码,我试图了解三种不同的数据绑定方式之间的区别。由于我是 angular4 的新手,我需要明确何时使用什么。例如分配 ngModel,使用 [(ngModel)]。要分配禁用属性,请使用 [disabled]。要分配 ngSubmit 处理程序,使用 (ngSubmit)。很难区分它们中的每一个。
<section class="sample-app-content">
<h1>Template-driven Form Example:</h1>
<form #f="ngForm" (ngSubmit)="onSubmitTemplateBased()">
<p>
<label>First Name:</label>
<input type="text"
[(ngModel)]="user.firstName" required>
</p>
<p>
<label>Password:</label>
<input type="password"
[(ngModel)]="user.password" required>
</p>
<p>
<button type="submit" [disabled]="!f.valid">Submit</button>
</p>
</form>
</section>
【问题讨论】:
标签: javascript angular angular4-forms