I have an array as collection and I want to load it within dropdown list & I want a default selection on some condition but I don't know how to achieve this.
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
<select name="" id="" style="position:relative; left: 100px">
<option *ngFor="let i of collection;" value="{{i}}" [selected]="i == Angular: 2">{{ i }}</option>
</select>
I want the drop down should be selected value of when i == Angular: 2
i == 'Angular: 2'.