AOT - ngc无法解析Component的所有参数

时间:2017-07-27 09:51:55

标签: angular aot angular-aot

当我使用以下JIT指令ng build构建时; ng build --prod当我使用--aot标记为{A}构建时,一切正常,ng build --aot该应用有效。 但是当我尝试使用ngc编译它(AOT)时,我得到了以下错误:

Can't resolve all parameters for HomeComponent in /appname/src/app/home/home.component.ts: (?).

这是HomeComponent类:

import {EventManager} from 'app/directives/EventManager.directive';
@Component({
  selector:'home',
  template:`
          ...
    `,
  styleUrls: ['./home.component.css']
})
    export class HomeComponent  {

      showLoggedBar:Boolean;
      constructor(private _eventManager:EventManager) {

        this._eventManager.showLoggedBar.subscribe((mode)=> {
          if(mode)
          {
            this._eventManager.showBar.emit(true);
            this.showLoggedBar = mode;
          }
        });
      }
    }

[已编辑] EventManager:

@Injectable()
export class EventManager {
    public showLoggedBar: EventEmitter<any> = new EventEmitter();
    public showLoggedDoBar: EventEmitter<any> = new EventEmitter();
    public showDoBar: EventEmitter<any> = new EventEmitter();
    public showBar:EventEmitter<any>=new EventEmitter();
    public dataSearch:EventEmitter<any>= new EventEmitter();
    public updateP:EventEmitter<any>=new EventEmitter();
    public updateD:EventEmitter<any>=new EventEmitter();
    public detailsAvailable:EventEmitter<any>= new EventEmitter();
    public infoAp:EventEmitter<any>= new EventEmitter();

  constructor() {
        this.showBar.emit(true);
    }
}

[EDITED] app.module.ts:

import{NgModule} from '@angular/core';
import {
  LocationStrategy,
  PathLocationStrategy
} from '@angular/common';
import { BrowserModule  } from '@angular/platform-browser';
import { AppComponent }   from './app.component';
import { routing,  appRoutingProviders } from './app.routing';
import { HomeComponent } from './home/home.component';
import { HttpModule } from '@angular/http';
import {EventManager} from '../app/directives/EventManager.directive';


@NgModule({
  declarations:
    [
      ...
      HomeComponent,
      ...
    ],
  imports:      [BrowserModule,HttpModule,...],
  bootstrap:    [AppComponent],
  providers:[
    ...
    EventManager,
    ...
  ]
})
export class AppModule {}

您是否知道错误的原因?

1 个答案:

答案 0 :(得分:1)

当您注入command时,您需要提供EventManager。提供EventManager毫无意义。

要注入GlobalEventManager个实例,请求GlobalEventManager时,请使用EventManager

useClass

如果有注入providers: [{ provide: EventManager, useClass: GlobalEventManager }] 的组件或服务,您可以使用GlobalEventManager来避免创建两个不同的实例:

useExisting