![](/img/trans.png)
[英]How to bind multiple values with same Id into single array in angular
[英]How can I bind multiple actions to a single Angular output?
如何在不創建任何其他方法的情況下將多個動作綁定到單個 Angular 輸出?
一個示例是根據自定義組件的輸出更新formControl
的值,並將該formControl
標記為臟。
您可以將數組綁定到 HTML 模板中的輸出,這使您能夠觸發多個操作:
模板:
<ul>
<li style="cursor:pointer"
*ngFor="let value of values"
(click)="[myFormControl.setValue(value), myFormControl.markAsDirty()]">{{value}}
</li>
</ul>
<ul>
<li>Form Control Value: {{myFormControl.value}}</li>
<li>Form Control Dirty: {{myFormControl.dirty}}</li>
</ul>
<button (click)="myFormControl.reset()">Reset Form Control</button>
成分:
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
myFormControl = new FormControl(null);
values = ['spring', 'summer', 'autumn', 'winter'];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.