我想使用页面上的选择元素创建导航。在锚标记上使用 RouterLink 指令很简单,但是选择下拉菜单是否有等效的指令?或者我是否需要在我的组件上创建自己的导航方法,以便在我的选择发生更改时调用?
<a [routerLink]="[location]">Location</a>
<select (change)="navigate($event.target.value)">
<option>--Select Option--</option>
<option [value]="[location]">Location</option>
</select>
我正在寻找这样的东西:
<select>
<option>--Select Option--</option>
<option [routerLink]="[location]">Location</option>
</select>
网页模板:
<select (change)="navigateTo($event.target.value)">
<option>--Select Option--</option>
<option value="location">Location</option>
</select>
成分:
import {Router} from '@angular/router-deprecated'; //or updated version
constructor(private router: Router){}
navigateTo(value) {
if (value) {
this.router.navigate([value]);
}
return false;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)