Angular 如何将回调作为函数传递
我正在尝试将回调作为函数参数传递 例如:Angular 如何将回调作为函数传递,angular,Angular,我正在尝试将回调作为函数参数传递 例如: public abc1(doc:any){ console.log('abc1'); } public abc2(model:any){ console.log('abcd2'); } xyz.load(id.replace('/', ''), abc1, abc2); 这里是abc1和abc2我的回调函数,我试图在xyz中传递这些函数。 它们都在同一个组件中
public abc1(doc:any){
console.log('abc1');
}
public abc2(model:any){
console.log('abcd2');
}
xyz.load(id.replace('/', ''), abc1, abc2);
这里是
abc1
和abc2
我的回调函数,我试图在xyz中传递这些函数。
它们都在同一个组件中。您可以这样定义加载方法:
load(id: string, callback1: (doc: any) => void, callback2: (model: any) => void) {
// do your stuff here
callback1(theDocument);
callback2(theModel);
}
这样称呼它:
xyz.load(id.replace('/', ''), abc1, abc2);
什么是回调1(文档);回调2(模型);这里是您的案例中的abc1
和abc2
<代码>文档
和模型只是占位符,因为我不知道它们来自哪里。