I'm trying to use the getDeep()
function in Angular. I have already used it elsewhere in my code but in this particular part of the code it causes a TypeError
. I would really appreciate it if someone can shed a light on why this is not working.
import { ConfigStateBase } from './config-state-base';
import { Injector } from '@angular/core';
import { ConfigStateService } from '@abp/ng.core';
export class RuleOutputState extends ConfigStateBase {
public readonly id: string;
public readonly value: string;
public readonly label: string;
public readonly imageUrl?: string;
public readonly fullImageUrl?: string;
public readonly position: number;
private readonly config: ConfigStateService;
constructor(injector: Injector, ruleOutputExport: any) {
super(injector);
this.id = ruleOutputExport.id;
this.value = ruleOutputExport.value;
this.label = this.translatorService.getLabel(ruleOutputExport.labels, this.value);
this.imageUrl = this.translatorService.getLabel(ruleOutputExport.images);
console.log(this.imageUrl);
this.fullImageUrl = this.createFullImageUrl(this.imageUrl);
console.log(this.fullImageUrl);
this.position = ruleOutputExport.position;
}
protected createFullImageUrl(imageUrl?: string): string {
if (!imageUrl) {
return null;
}
else {
return `${this.config.getDeep('environment.application.questionImagesUrl')}/${imageUrl}`;
}
}
}
CodePudding user response:
Your config
object is undefined
.
You should probably pass it in the constructor, in order to be injected !
constructor(private readonly config: ConfigStateService, injector: Injector, ruleOutputExport: any) {
...
}
CodePudding user response:
Adding the following line inside the constructor resolved my problem:
this.config = injector.get(ConfigStateService);