我正在try 让我的SELECT标记将我重定向到一个值为option
的URL.例如,以下是我的代码:
<select #selectElement (change)="redirectToUrl(selectElement.value)">
<option value="/add-product">Add a product</option>
</select>
而在.Component.ts中是:
@ViewChild('selectElement', { static: false })
selectElement!: ElementRef;
redirectToUrl(url: String) {
if (url){
const urlTree: UrlTree = this.router.createUrlTree([url]);
this.router.navigateByUrl(urlTree);
}
}
而OFC,当我 Select 该选项时,没有任何react .我不知道我错过了什么.