ausgeführt Wenn ich meinen Dienst im Konstruktor aufgerufen, bekomme ich undefiniert. der Service wird in ngOnInit
Methode aufgerufen, Von Difference between Constructor and ngOnInit Ich habe gesehen, dass Konstruktor zuerst ausgeführt, aber in meinem Fall bemerkte ich das Gegenteil, also bin ich etwas verwirrt. habe jemand mehr Erklärung darüber, danke.ngOnInit und Konstruktor wer zuerst
constructor(private curveService :ProgressCurveService, private util : UtilService) {
this.startPickerOptions = new DatePickerOptions();
this.endPickerOptions = new DatePickerOptions();
//this.datePickerOptions.initialDate = new Date(Date.now());
}
ngOnInit() {
this.curveService.instance.getCurve(this.startDate.formatted,this.endDate.formatted,this.amplutid).
then(res => {
this.lineChartLabels = this.util.dateToShortString(Object.keys(res.progressPlotData))
this.lineChartData = this.util.objectToIntArray(res.progressPlotData);
}).catch(res => console.log('error if date selecting ...'));
}
Verlaufskurve Service:
import { progressCurveItf } from './progress-curve/progress-curve-interface';
@Injectable()
export class ProgressCurveService {
state : string = 'project';
constructor(private prsCurve : PrsProgressCurveService, private projCurve : ProjProgressCurveService) { }
get instance():progressCurveItf{
if(this.state == 'subproject'){
return this.prsCurve;
} else {
return this.projCurve;
}
}
}
Der Konstruktor wird zuerst ausgeführt. Das Problem muss von woanders kommen. –
genau, bereits in der Dokumentation auch erläutert, dass der Konstruktor zuerst ausgeführt –
Ich bekomme kann nicht lesen Eigenschaftsinstanz von undefiniert Ausnahme – mustafa918