gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 22:15:27 25 4
gpt4 key购买 nike

我试图构建我的 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
)
{}
............
.....
}

最佳答案

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]).


?错误消息中的问号告诉构造函数中的哪个参数是未知的。
constructor(
protected _systemListTitle : string,
protected _svc: SimpleLookupBaseService,
protected _router: Router,
protected _route: ActivatedRoute
)

第一个参数是触发 ?问号。

类型 string不是可注入(inject)的类型。 Angular 注入(inject)器使用参数的类型来推断 injectable应使用的提供程序。

注入(inject) string参数,您必须在您的 NgModule 之一中提供一个 token 定义。
export const LIST_TITLE: InjectionToken<string> = new InjectionToken<string>('LIST_TITLE');

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

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

关于Angular - 无法解析组件 ng build --prod 的所有参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51275878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com