app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'project';
getName(name)
{
alert(name);
}
}
app.component.html
<button (click)="getName('tony')">click me</button>
我是 Angular 新手,我使用的是 12.1.4 版本。现在,如果我只是使用点击事件而不在内部传递参数,那么这里会发生什么getName(),alert("anything")然后它会完美运行。click但是当我尝试在函数内部传递参数并在我的事件函数中赋值时。然后它抛出一个错误,即Parameter 'name' has implicitly had an 'any' type。请帮我解决这个问题。