我尝试为我的 Angular 应用编写自定义函数。 我已经按照官方指南创建了一个独立的库。
我打算像这样编写可链接的函数
var obj = {
test : function(){
console.log('1');
return this;
},
test2 : function(){
console.log('2');
return this;
}
}
obj.test().test2();
如何在 Angular 中导出和导入可链接的方法?我应该编写此自定义函数的正确文件类型是什么?例如,可能是服务、模型或组件?
谢谢
最佳答案
How to export and import a chainable method in Angular
如果您关心推断类型安全,请使用类:
class Obj {
test() {
console.log(1);
return this;
}
test2() {
console.log(2);
return this;
}
}
new Obj().test().test2();
And which is the correct file type that I should write this custom function? For example, might be service, model, or component?
在任何 .ts
文件中。简单地导出例如:
export const obj = new Obj();
关于javascript - 在 Angular 中编写可链接函数的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52049932/