Angular 角式喷油器未通过deps
我的喷油器有问题 我构建了一个抽象类,它是自定义组件的基础。这就是为什么对于构造函数,我使用Angular 角式喷油器未通过deps,angular,Angular,我的喷油器有问题 我构建了一个抽象类,它是自定义组件的基础。这就是为什么对于构造函数,我使用Injector——用于simplyfiy子类 export abstract class SchematerLayout implements OnInit, AfterViewInit { @Input() public form: FormGroup; @Input() public field: IFieldConfig; @ViewChild('fieldComponen
Injector
——用于simplyfiy子类
export abstract class SchematerLayout implements OnInit, AfterViewInit {
@Input() public form: FormGroup;
@Input() public field: IFieldConfig;
@ViewChild('fieldComponent', {read: ViewContainerRef}) fieldComponent: ViewContainerRef;
constructor(protected injector: Injector) {
}
ngOnInit() {
const componentResolver = this.injector.get(SchematerComponentResolverService);
const validationMessagesService = this.injector.get(SchematerValidationMessagesService);
}
}
问题是SchematerValidationMessageService
gets always错误无法解析SchematerValidationMessageService:(?)的所有参数。
SchematerComponentResolversService依赖于同一个服务
这是我的schematerValidationMessageService
类:
@Injectable()
export class SchematerValidationMessagesService {
constructor(
protected configService: SchematerConfigService
) {
}
getErrorMessage(fieldControl: AbstractControl, fieldConfig: IFieldConfig) {
//...
}
}
@Injectable()
export class SchematerComponentResolverService {
constructor(protected componentFactoryResolver: ComponentFactoryResolver,
protected configService: SchematerConfigService
) {
}
createLayoutComponent(type: string) {
// console.log(type);
}
}
和SchematerComponentResolverService
class:
@Injectable()
export class SchematerValidationMessagesService {
constructor(
protected configService: SchematerConfigService
) {
}
getErrorMessage(fieldControl: AbstractControl, fieldConfig: IFieldConfig) {
//...
}
}
@Injectable()
export class SchematerComponentResolverService {
constructor(protected componentFactoryResolver: ComponentFactoryResolver,
protected configService: SchematerConfigService
) {
}
createLayoutComponent(type: string) {
// console.log(type);
}
}
我正在使用forRoot
策略获取提供商:
static forRoot(config: SchematerConfig): ModuleWithProviders {
return {
ngModule: SchematerInputModule,
providers: [
{
provide: SchematerConfig,
useValue: config,
},
{
provide: ANALYZE_FOR_ENTRY_COMPONENTS,
useValue: config,
multi: true
},
SchematerConfigService,
SchematerValidationMessagesService,
SchematerComponentResolverService,
]
};
}
谁能告诉我为什么
SchematerConfigService
可用于第一个服务而不可用于第二个服务?这意味着SchematerConfigService
在执行过程中未定义SchematerValidationMessagesService
类。您很可能有循环依赖关系,但为什么它可以更早地使用?我批准了completeSchematerValidationMessagesService
类-在github上的最小示例中没有其他依赖创建复制。用户在准备最小复制时经常发现自己的编码问题。问题是我的entryComponents有依赖性。我得做些改变-谢谢