[英]Service inheritance with Angular 1.x and ES6
I am using Angular 1.6 with ES6. 我在ES6中使用Angular 1.6。 Until now I implemented inheritence with the
extend
keyword on ES6 classes 到目前为止,我在ES6类上使用
extend
关键字实现了继承
export default class myChildService extends myBaseService {
constructor(someDependency){
'ngInject'
super();
someDependency.doStuff();
}
}
and registered the child-class as angular-service 并将儿童班注册为角度服务
import myChildService from ./myChildService
angular.module('myApp', [])
.service('myChildService', myChildService)
This works well so far! 到目前为止效果很好!
However I would like to split my application into smaller modules. 但是,我想将我的应用程序拆分为较小的模块。 This means I will have several different angular-modules which will need access to
myBaseService
in order to inherit the functionality. 这意味着我将有几个不同的angular-modules,它们需要访问
myBaseService
才能继承功能。
I could just import
the file containing myBaseService
, but this seems not very angulary. 我可以只
import
包含myBaseService
的文件,但这似乎不太合适。 It basically means I disregard angular-modules and DI everytime I use inheritance. 基本上,这意味着我每次使用继承时都无需理会angular-modules和DI。
Question: 题:
Is there any way to export an ES6-class from an angular-module base
so that I can reuse it on an angular-module child
which depends on base
? 有什么方法可以从angular-module
base
导出ES6-class,以便我可以在依赖base
的angular-module child
上重用它。
Maybe I am just looking at this the wrong way - if you have other suggestions to implement inheritance of angular-services/ factories using ES6-classes , please go ahead. 也许我只是在以错误的方式看待-如果您还有其他建议使用ES6类来实现angular-services / factory的继承,请继续。
Why importing is not angulary? 为什么导入不是有角度的? If you would like to use base service functionality, the module should know it's definition.
如果您想使用基本服务功能,则模块应知道其定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.