Angular - 无法解析组件所有参数 ng build --prod

4
我正在尝试构建我的angular应用程序,但由于此错误而失败。
 ERROR in : Can't resolve all parameters for SimpleLookupAddEditFormComponent 
 in C:/Users/lastr/Source/Repos/SMATA/Code/ng/smata-ng/src/app/system- 
 list/simple-lookup-add-edit/simple-lookup-add-edit.component.ts: (?, [object 
 Object], [object Object], [object Object]).

这是组件的代码。这是一个基础组件。这里有什么缺失吗?也许构造函数属性存在问题?

 import { Component, OnInit } from '@angular/core';
 import { SimpleLookupBaseService } from '../services/simple-lookup-base/simple-lookup-base.service';
 import { ActivatedRoute, Router } from '@angular/router';
 import validationEngine from "devextreme/ui/validation_engine";
 import notify from 'devextreme/ui/notify';

 @Component({
   selector: 'app-simple-lookup-add-edit',
   templateUrl: './simple-lookup-add-edit.component.html',
   styleUrls: ['./simple-lookup-add-edit.component.css']
 })
 export class SimpleLookupAddEditFormComponent implements OnInit {

   newSystemList: {};
   isEditMode:boolean = true;
   selectedSystemList: any;
   title: string;
   saveButtonText: string;
   isPopupVisible:boolean = false;
   entityId:any;

   constructor(
     protected _systemListTitle : string,
     protected _svc: SimpleLookupBaseService,
     protected _router: Router,
     protected _route: ActivatedRoute
   ) 
     {}
 ............
 .....
 }
1个回答

5

错误:在C:/Users/lastr/Source/Repos/SMATA/Code/ng/smata-ng/src/app/system-list/simple-lookup-add-edit/simple-lookup-add-edit.component.ts中无法解析SimpleLookupAddEditFormComponent的所有参数:(?,[object Object],[object Object],[object Object])。

错误信息中的?问号表示构造函数中哪个参数是未知的。

constructor(
 protected _systemListTitle : string,
 protected _svc: SimpleLookupBaseService,
 protected _router: Router,
 protected _route: ActivatedRoute
) 

第一个参数触发了“?”问号。
类型“string”不是可注入的类型。Angular注入器使用参数的类型来推断应该使用哪个“injectable”提供程序。
要注入一个“string”参数,您必须在其中一个“NgModule”定义中提供一个标记。
export const LIST_TITLE: InjectionToken<string> = new InjectionToken<string>('LIST_TITLE');

@NgModule({
   providers: [{provide: LIST_TITLE, useValue: 'My List Title'}]
})

现在,您可以手动将令牌注入到构造函数中。
constructor(
 @Inject(LIST_TITLE) protected _systemListTitle : string,
 protected _svc: SimpleLookupBaseService,
 protected _router: Router,
 protected _route: ActivatedRoute
) 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接