如何使用angularjs 1.5 es6注入服务
我知道如何从控制器中的服务中为这样的特定组件调用方法如何使用angularjs 1.5 es6注入服务,angularjs,Angularjs,我知道如何从控制器中的服务中为这样的特定组件调用方法 import template from './tech.html' import styles from './styles.mcss' import TechService from './techService'; class Controller { constructor(TechService) { // css modules TechService.consoleLog(); this.sty
import template from './tech.html'
import styles from './styles.mcss'
import TechService from './techService';
class Controller {
constructor(TechService) {
// css modules
TechService.consoleLog();
this.styles = styles;
}
}
export const tech = {
template,
bindings: {
tech: '<'
},
controller: Controller
};
我的应用程序的根就是这个
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';
angular
.module('myApp', [
// dependencies
uiRouter, ngAnimate, ngTouch, uiBootstrap,
// modules
componentsModule,
commonModule,
techsModule
])
.config(routesConfig);
我想知道在哪里注入以及我的service TechService如何调用我的方法consoleLog()最简单的解决方案是使用数组表示法:
export const tech = {
template,
bindings: {
tech: '<'
},
controller: ['TechService', Controller]
};
export const tech={
模板,
绑定:{
tech:“angularjs如何知道字符串('TechService')我应该将TechService作为服务添加到模块TechModule中?我看到techsModule
已经是应用程序模块的一部分,所以这很好。
export const tech = {
template,
bindings: {
tech: '<'
},
controller: ['TechService', Controller]
};