Answer the question
In order to leave comments, you need to log in
How to create and consume an Angular 2 Service in a Service (ES5)?
It is important that the code be in JavaScript (ES5).
There is a project service (ProjectsService) and a project file service (FilesService) that depends on it. The file service will be called in the child component of the projects component.
Those.
app.ProjectsService = ng.core
.Class({
constructor: function ProjectsService() { ... }
});
app.FilesService = ng.core
.Class({
constructor: [app.ProjectsService, function FilesService(projectsService) {
this._projectsService = projectsService;
...
}]
});
app.Cmp = ng.core
.Component({
...,
"providers" : [app.FilesService] //ProjectsService возьмем у родительского компонента
})
.Class({
constructor: [
app.FilesService, // каким образом передать экземпляр ProjectsService родительского компонента?
function(filesService) {
this._filesService = filesService;
...
}
]
});
Answer the question
In order to leave comments, you need to log in
It turned out to be very simple:
app.Cmp = ng.core
.Component({
...,
"providers" : [app.FilesService] //ProjectsService возьмем у родительского компонента
})
.Class({
constructor: [
app.ProjectService,
app.FilesService,
function(projectService, filesService) {
this._projectService = projectService;
this._filesService = filesService;
...
}
]
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question