• 赚钱入口【需求资源】限时招募流量主、渠道主,站长合作;【合作模式】CPS长期分成,一次推广永久有收益。主动打款,不扣量;

Uncaught ReferenceError: onSelect is not defined at HTMLAnchorElement.onclick

CSS/HTML rin, seun 1年前 (2020-08-18) 459次浏览 0个评论

控制台打印错误:

Uncaught ReferenceError: onSelect is not defined
    at HTMLAnchorElement.onclick (VM998 :14)

我在.html文件中的列表数据

<ul class="nav navbar-nav">
                <li><a href="#" onclick="onSelect('Recipe')">Recipe</a></li> 
                <li><a href="#" onclick="onSelect('Shoppinglist')" id="ShoppingOnSelect">Shopping List</a></li>
            </ul>

在调用此函数,Angular js中的My Typescript文件时,

export class HeaderComponent{
    @Output() featureSelected = new EventEmitter<String>();

    onSelect(feature: string){
        console.log(feature)
        this.featureSelected.emit(feature);
    }

}

当我单击onclick时,Onselect函数本身未在控制台中运行

解决方案

It should be (click)

<li><a href="#" (click)="onSelect('Recipe')">Recipe</a></li>

If you want to prevent the href=”#” reloading the page:

<li><a href="#" (click)="!!onSelect('Recipe')">Recipe</a></li>

And also you can use replace href=”#” with [routerLink]=”” which is an alternative

<li><a [routerLink]="" (click)="!!onSelect('Recipe')">Recipe</a></li>
喜欢 (2)

您必须 登录 才能发表评论!