khalil _diouri khalil _diouri - 1 year ago 115
AngularJS Question

How inject a service using angularjs 1.5 es6

I how to call a method from my service in my controller for a specific component like this

import template from './tech.html'
import styles from './styles.mcss'
import TechService from './techService';

class Controller {

constructor(TechService) {
// css modules

this.styles = styles;

export const tech = {
bindings: {
tech: '<'
controller: Controller

this it not works where should I inject and how to inject TechService

this controller is a component of this module

import angular from 'angular';

import {tech} from './tech';
import {techs} from './techs';
export const techsModule = 'techs';

.module(techsModule, [])
.component('fountainTech', tech)
.component('fountainTechs', techs);

and the root of my app is this

import angular from 'angular';
import uiRouter from 'angular-ui-router';
import ngAnimate from 'angular-animate'
import ngTouch from 'angular-touch'
import uiBootstrap from 'angular-ui-bootstrap';

import {componentsModule} from './components';
import {commonModule} from './common';
import {techsModule} from './techs'
import TechService from './techs/techService';

import routesConfig from './routes';

import './index.scss';

.module('myApp', [
// dependencies
uiRouter, ngAnimate, ngTouch, uiBootstrap,

// modules

I want to know where to inject and how my service TechService to call my method consoleLog()

Answer Source

The simplest solution is to use array notation:

export const tech = {
  bindings: {
    tech: '<'
  controller: ['TechService', Controller]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download