How pass 2 parameters to EventEmitter angular2

前端 未结 4 559
慢半拍i
慢半拍i 2020-12-14 05:35

I have in my component an EventEmitter but I can\'t compile it because it return the error: Supplied parameters do not match any signature of call target<

4条回答
  •  温柔的废话
    2020-12-14 06:00

    Another option to strongly type it is as follows:

    @Output addModel = new EventEmitter<{make: string, name: string}>();

    you can then emit it like @Pankaj-Parkar shows

    this.addModel.emit({make, name});
    or
    this.addModel.emit({make: 'honda', name: 'civic'});

    You now have strong typing instead of using object or any.

提交回复
热议问题