我有一个控件组件,我想将此实际控件保存在控件列表中。
我正在尝试在事件发射器中传递当前组件
@Output() passthings: EventEmitter,<{any, MyComponent}> new EventEmitter();
然后用我的方法
loadStuff(){
var component = this;
this.service.getStuff().subscribe(response =>{
this.passthings.emit({response, component}); <-----Errors here
}
单词response带有错误下划线 “类型'{response的参数不能分配给类型'{任何:任意; MyComponent:任何;}”的参数
答案 0 :(得分:3)
尝试:
@Output() passthings: EventEmitter<any> = new EventEmitter<any>();
或者也许,您可以定义接口...
interface myEmittedObject{
response: any;
control: any;
}
...和这样的EventEmitter
@Output() passthings: EventEmitter<myEmittedObject> = new EventEmitter<myEmittedObject>();
该接口可以嵌套以更详细:
interface myEmployeeData {
id: string;
name: string;
age: number;
active: boolean;
...etc.
}
interface myEmittedObject{
response: myEmployeeData ;
control: any;
}