簡體   English   中英

如何使用反應式 forms 在 Angular 多選上設置選擇?

[英]How to set selections on an Angular multiselect with reactive forms?

解釋該問題的最佳方式...在此 StackBlitz 中,我想將選擇設置為“佛羅里達”並查看該選項是否已選中。

https://stackblitz.com/edit/angular-multi-select-dropdown-reactive-forms-jb7x2h?file=src%2Fapp%2Fapp.component.html

我能夠從 FormControl 設置和獲取值,但在視覺上 select 沒有顯示正確選擇的選項。

我在這里為你寫了一些東西(分叉了你的閃電戰)。 這應該適合你。

https://stackblitz.com/edit/angular-multi-select-dropdown-reactive-forms-tgwe3n?file=src%2Fapp%2Fapp.component.ts

如果您需要其他東西,請告訴我

只有您必須訪問要更新的屬性,在本例中是 app.component.html 上第 43 行的屬性

{{ registrationForm?.getRawValue().cityName }}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM