[英]Service inheritance with Angular 1.x and ES6
我在ES6中使用Angular 1.6。 到目前为止,我在ES6类上使用extend
关键字实现了继承
export default class myChildService extends myBaseService {
constructor(someDependency){
'ngInject'
super();
someDependency.doStuff();
}
}
并将儿童班注册为角度服务
import myChildService from ./myChildService
angular.module('myApp', [])
.service('myChildService', myChildService)
到目前为止效果很好!
但是,我想将我的应用程序拆分为较小的模块。 这意味着我将有几个不同的angular-modules,它们需要访问myBaseService
才能继承功能。
我可以只import
包含myBaseService
的文件,但这似乎不太合适。 基本上,这意味着我每次使用继承时都无需理会angular-modules和DI。
题:
有什么方法可以从angular-module base
导出ES6-class,以便我可以在依赖base
的angular-module child
上重用它。
也许我只是在以错误的方式看待-如果您还有其他建议使用ES6类来实现angular-services / factory的继承,请继续。
为什么导入不是有角度的? 如果您想使用基本服务功能,则模块应知道其定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.