Answer the question
In order to leave comments, you need to log in
How to properly inject dependencies in es6?
I came close to AngularJS for the first time and I experience difficulties, for some reason, at every step.
I have custom-service.js in which is the following code -
export class CustomService {
constructor(){
}
}
export function customDirective(/*как мне тут получить CustomService?*/){
return {
///...
};
}
export const app = angular.module('app', []);
import {app} from 'app.js';
import {CustomService} from 'custom-service.js';
import {customDirective} from 'custom-directive.js';
app.service('customService', [CustomService]);
app.directive('customDirective', [customDirective]);
angular.bootstrap(document, [app]);
How to get 'customService' in customDirective? Answer the question
In order to leave comments, you need to log in
// custom.directive.js
/** @ngInject */
export default function(customService){
return {
///...
};
}
// app.module.js
angular
.module('app')
.service('customService', require('./custom.service.js'))
.directive('customDirective', require('./custom.directive.js'))
;
// bootstrap.js
import './app.module';
angular.bootstrap(document, [app]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question