当尝试使用webpack进行生产编译时出现问题(可以使用velopment编译)。我遇到一个错误:“
[$ injector:unpr]:tProvider <-t”。
这是我的代码:
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...
}
}