生产编译时出现未知的提供程序错误-带有Typescript的AngularJs

时间:2019-11-05 12:30:19

标签: angularjs typescript webpack

生产编译时出现带有Typescript错误的AngularJs

当尝试使用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...
   }
}

0 个答案:

没有答案