以下是我的问题的示例
sample.component.html
<div class="center">
<div class="form-group" >
<label>Select Country</label>
<select class="form-control">
<option *ngFor="let o of options">{{o.name}}</option>
</select>
<button><a [routerLink]="[o.value]">Submit</a></button>
</div>
</div>
sample.component.ts
export class SelectLocationComponent {
selectedOption: string;
options = [
{ name: "All Countries", value: '/allcountries' },
{ name: "India", value: '/india' }
]
}
我希望在routerlink
中选择o.value
来自sample.component.ts
答案 0 :(得分:1)
像这样在ngmodel
内使用routerlink
变量
<div class="center">
<div class="form-group">
<label>Select Country</label>
<select class="form-control" [(ngModel)]="selectedOption">
<option *ngFor="let o of options" [value]="o.value">{{o.name}}
</option>
</select>
<button><a [routerLink]="selectedOption">Submit</a></button>
{{selectedOption}}
</div>
</div>