【发布时间】:2018-12-12 03:22:48
【问题描述】:
我有一个咖啡馆模型,我想将其显示为咖啡馆列表中的默认值。这是我的代码
<div class="form-group">
<label for="theme" style="margin-top: 20px;">Cafe Name</label>
<select class="form-control" [ngModel]="cafeList" (ngModelChange)="changeCafe($event)" name="cafe">
<option *ngFor="let cafe of cafeList" [ngValue]="cafe">{{cafe.name}}</option>
</select>
<a href="" style="margin-top: 10px;" [routerLink]="['/cafe/edit-cafe', selectedCafe.cafeId]" class="btn btn-warning">
<i class="ti-comment pdd-right-5"></i>
<span>View Cafe</span>
</a>
</div>
为了检索数据,我正在做这样的事情
const data = d[0];
this.ad = <AdsItem> data.payload.val();
this.selectedCafe = this.ad.cafe;
this.cafeId = this.ad.cafe.cafeId;
this.subscription = this.db.list<CafeItem>('cafeList').snapshotChanges().subscribe(d=>{
this.cafeList = [];
d.forEach(data =>{
var user = <CafeItem> data.payload.val();
this.cafeList.push(user);
});
});
现在我不确定如何将 selectedCafe 设置为默认咖啡馆
【问题讨论】:
-
ngModel应该是字符串而不是数组