作者:骑单车追梦的小男孩 | 来源:互联网 | 2022-11-30 10:25
我有一个数组作为集合,我想将其加载到下拉列表中,并希望在某种情况下进行默认选择,但我不知道该如何实现。
app.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-commingsoon',
templateUrl: './commingsoon.component.html',
styleUrls: ['./commingsoon.component.css']
})
export class CommingsoonComponent implements OnInit {
public collection = [];
constructor() {
for(let i = 1; i<=10 ; i++) {
this.collection.push(`Angular: ${i}`);
}
}
ngOnInit() {
}
}
app.component.html
我希望下拉列表应为i == Angular:2时的选定值
1> Boland..:
缺少引号,请尝试 i == 'Angular: 2'
或者,如果您只对索引感兴趣: