Using [(ngModel)]
, I managed to set an inputs value based on a selected dropdown but I'm getting an error when compiling using ng build --configuration=prod
, error shown is
Property 'name' does not exist on type 'any[]'
Property 'value' does not exist on type 'any[]'
when I compiled using ng serve
, there was no error, Here is a stackblitz I created and what I have tried so far,
Typescript file:
savedCards = [];
selectedCard = '';
selectDropdownCard(card) {
this.savedCards.find((item) => item.id === card.id) ?
this.savedCards = this.savedCards.filter((item) => item.id === card.id) :
this.savedCards = [card];
this.show = false;
this.hasSelected = true;
this.selectedCard = card;
}
HTML file
<div class="div1" (click)="selectSavedCard()" [(ngModel)]="selectedCard" ngDefaultControl>
<div *ngIf='!hasSelected'>
<div>
<p>dropdown</p>
</div>
</div>
<div *ngFor="let card of savedCards">
<div>
<p>{{card.viewValue}}</p>
</div>
</div>
</div>
<div class="div2" *ngIf="show">
<div *ngFor="let card of savedCreditCards" (click)="selectDropdownCard(card)">
<div>
<p>{{card.viewValue}}</p>
</div>
</div>
</div>
<input placeholder="id" [(ngModel)]="selectedCard.id" type="text">
<input placeholder="viewValue" [(ngModel)]="selectedCard.viewValue" type="text">
<input placeholder="name" [(ngModel)]="selectedCard.name" type="text">
<input placeholder="value" [(ngModel)]="selectedCard.value" type="text">
if I try added interface and use it as type, on ng build --configuration=prod
I got no error, but on ng serve
error shown are:
TypeError: Cannot read property 'value' of undefined
I could use some guidance and suggestions since I could not figure out how to solve this.