我有一个类似的组件类
import {Component, OnInit} from '@angular/core';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styles: []
})
export class LoginComponent {
message = "";
onClick() {
this.message = 'Hey, How are You?';
console.log(this.message);
alert(this.message);
}
}
和html中的按钮类似
<button type="button" class="btn btn-primary btn-lg" (click)="onClick()">Login to Dashboard</button>
但是,当单击按钮时,我得到了错误提示
ERROR TypeError: _co.onClick is not a function at Object.eval [as handleEvent]
答案 0 :(得分:0)
由于某种原因,模板看不到您的onClick()函数。当我遇到此错误时,这是因为我尚未编写函数。对您来说,可能是因为您的html模板格式错误