我不得不使用Angular 1.5和TypeScript创建一个应用程序。我对TypeScript非常陌生,并尝试将服务注入控制器。
目前正在获取Cannot find name 'AppService'
控制器:
class HomeController {
static $inject = ['AppService'];
private apps: Object[];
constructor(AppService: AppService) {
AppService
.getApps()
.success((apps) => this.apps);
}
}
export default HomeController;
索引文件:
import * as angular from 'angular';
import HomeComponent from './home.component';
import {AppService} from '../../services/app.service';
const home = angular
.module('main.app.home', [])
.component('home', HomeComponent)
.service('AppService', AppService)
.config(($stateProvider) => {
$stateProvider
.state('app', {
url: '/',
template: '<home></home>'
});
})
.name;
export default home;
service.modules:
import * as angular from 'angular';
import {AppService} from './app.service';
const services = angular
.module('main.app.services', [])
.service('AppService', AppService)
.name;
export default services;
不确定我做错了什么。如果我在控制器中导入服务我可以访问它没有问题...但是当我尝试将其注入时,我得到了该错误。我错过了什么?