我最近实现了一个 Angular 17 项目
我想为输出设置一个逻辑名称,但我不能,并且出现错误
这是我的代码行,它给别名带来了错误
import { Component, EventEmitter, Input, Output } from '@angular/core';
@Component({
selector: 'app-custom-btn',
templateUrl: './custom-btn.component.html',
styleUrl: './custom-btn.component.scss'
})
export class CustomBtnComponent {
@Output({alias : 'onClick'}) clickBtnProject = new EventEmitter();
clickBtn() {
this.clickBtnProject.emit();
}
}
错误文字如下
@Output decorator argument must resolve to a string Value is of type '{ alias: string }'.
__________________
Argument of type '{ alias: string; }' is not assignable to parameter of type 'string'.ts(2345)
其实你可以只给出一个不同名称的字符串,它将被视为别名,也可以提供相同的名称!
@Output('onClick') clickBtnProject = new EventEmitter();