Angular:输出绑定不应使用别名

问题描述 投票:0回答:1

我最近实现了一个 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();
  }

}

enter image description here

错误文字如下

@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)
angular typescript
1个回答
0
投票

其实你可以只给出一个不同名称的字符串,它将被视为别名,也可以提供相同的名称!

输出文档

@Output('onClick') clickBtnProject = new EventEmitter();
© www.soinside.com 2019 - 2024. All rights reserved.