生产编译时出现带有Typescript错误的AngularJs
当尝试使用webpack进行生产编译时出现问题(可以使用velopment编译)。我遇到一个错误:“
[$ injector:unpr]:tProvider
这是我的代码:
App.ts:
import * as angular from "angular";
const app = angular.module("app",[require('angular-animate')]);
import { productsService } from "./services/productsService";
app.service("productsService",productsService);
import { dataService } from "./services/dataService";
app.service("dataService",["$rootscope",dataService]);
import { ProductsComponent } from "./components/ProductsComponent";
app.component("productscomponent",new ProductsComponent());enter code here
产品服务:
export class productsService {
constructor() {}
products():Array<IProduct> {
const array:Array<IProduct> = [
//...array of products
];
return array;
}
}
数据服务:
//imports...
export class dataService {
static $inject = [
'$rootscope'
];
constructor($rootscope: ng.IrootscopeService) {
/...
}
//methods in service...
}
产品组件:
//import
export class ProductComponent implements ng.IComponentOptions {
//variables...
constructor() {
this.controller = ProductsComponentController;
this.controllerAs = "$ctrl";
this.template = `
//template...
`;
}
}
ProductsComponentController:
//imports
export class ProductsComponentController implements ng.IComponentController {
//variables...
constructor($rootscope: ng.IrootscopeService,dataService:dataService,productsService:productsService) {
//...
}
public $onInit ():void {
//variables...
//methods...
}
}