0
私のサービスをコンストラクタに注入すると、私は定義されません。 メソッドから サービスが呼び出されました。投稿者:Difference between Constructor and ngOnInit私はそのコンストラクタが最初に実行されるのを見ましたが、私の場合は反対に注意しました。誰かにそれについてのより詳細な説明を、ありがとう。ngOnInitと最初に実行したコンストラクタ
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 ...'));
}
進行曲線のサービス:
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;
}
}
}
コンストラクタが最初に実行されます。問題は他のどこかから来なければならない。 –
正確には、既にドキュメントでも説明済みですコンストラクタが最初に実行されます –
が取得されました未定義のプロパティインスタンスを読み取ることができません例外 – mustafa918