角度 2/4 - 带有复选框的引用变量的奇怪行为



此代码不起作用!

<input type="checkbox" value="1" #c>
<div *ngIf="c.checked">Show if checkbox is checked</div>

但这行得通!为什么??!

<input type="checkbox" value="1" (change)="true" #c>
<div *ngIf="c.checked">Show if checkbox is checked</div>

只有当应用程序执行某些操作以响应异步事件(例如击键、单击、更改、xmlhttprequest、setTimeout、Promise.then 等(时,Angular 才会更新绑定(因此也会更新屏幕((另请参阅 Angular 2 中 Zone 的用途.js(

虽然语句(change)="true"在您的第二个示例中没有任何用处,但它满足了 Angular 的要求,因此 Angular 将更新屏幕。有关更多详细信息,请参阅角度模板中的引用变量。

最新更新