0
我有一個場景,人可以有多個地址。當選擇地址類型完整地址顯示在文本區域時,在下拉菜單中顯示地址類型。嵌套模型 - 角2
<div *ngFor="let person of persons">
<select [ngModel]="selectedAddress" (ngModelChange)="selectedAddress = $event">
<option *ngFor="let address of person.addresses" [ngValue]="address">
{{address.type}}
</option>
</select>
<textarea [(ngModel)]="selectedAddress.address"></textarea>
</div>
每個人都顯示在每個div區塊中。當在一個塊上選擇下拉值時,也會填充其他塊中的文本區域。
當在一個塊上選擇下拉菜單時,應該只在塊內填充文本區域。如何處理這種情況
Pujol Ferriol - 我得到這個,當我嘗試實施你的建議。錯誤TypeError:無法讀取null的屬性'0'。有沒有我缺少的任何類型的空檢查。 – Ahelp
您必須在component.ts中啓動selectAddress數組。例如:private selectedAddress = [] –
是否可以處理兩維數組場景。例如,萬一如果我的對象是模型selectedAddress = [] [] – Ahelp