Angular 5 在编辑表单中从数据库填充选定的选项
Angular 5 populate selected option from database in edit form
我能够列出并添加 select 选项,如下所示:
<select class="form-control" [(ngModel)]="feed.feed_store" name="feed_store" placeholder="Select Store">
<option *ngFor="let feedstore of feedstores" [value]="feedstore">{{ feedstore }}</option>
</select>
现在,在我的编辑表单中,我想显示数据库中的 selected 选项。
不确定
您可以将 selected
属性设置为基于条件的选项,如下所示:
{{ 饲料店 }}
您可以将 selected
属性设置为基于条件的选项,如下所示:
<ng-container *ngIf="feed">
<select class="form-control" [(ngModel)]="feed.feed_store" name="feed_store" placeholder="Select Store">
<option *ngFor="let feedstore of feedstores"
[value]="feedstore"
[selected]="feedstore === 'feedstore_from_database'">
{{ feedstore }}
</option>
</select>
<ng-container>
我能够列出并添加 select 选项,如下所示:
<select class="form-control" [(ngModel)]="feed.feed_store" name="feed_store" placeholder="Select Store">
<option *ngFor="let feedstore of feedstores" [value]="feedstore">{{ feedstore }}</option>
</select>
现在,在我的编辑表单中,我想显示数据库中的 selected 选项。 不确定
您可以将 selected
属性设置为基于条件的选项,如下所示:
{{ 饲料店 }}
您可以将 selected
属性设置为基于条件的选项,如下所示:
<ng-container *ngIf="feed">
<select class="form-control" [(ngModel)]="feed.feed_store" name="feed_store" placeholder="Select Store">
<option *ngFor="let feedstore of feedstores"
[value]="feedstore"
[selected]="feedstore === 'feedstore_from_database'">
{{ feedstore }}
</option>
</select>
<ng-container>