I have a problem, maybe I don't understand how to do but when I try to catch data from an HttpRequest during angular ngOnInit, my console.log return me an "undefined" value. The thing is that when I use this value in my template view it works !
Here is my Component
export class ReferentielFormComponent implements OnInit {
id: number;
currentUser;
referentiel;
progressValue: number;
formGroup: FormGroup;
isNew: boolean;
constructor(private service: AppService,
private referentiels: ReferentielService,
private router: ActivatedRoute,
private config: NgbTabsetConfig) {
}
ngOnInit() {
this.router.params.subscribe((params: Params) => this.id = params['id']);
if (this.id) {
this.referentiels.getReferentiel(this.id).subscribe(data => this.referentiel = data);
} else {
this.referentiel = {};
}
this.isNew = !this.referentiel;
console.log(this.referentiel);
console.log(this.isNew);
this.progressValue = 20;
this.formGroup = new FormGroup({
titre: new FormControl(!this.isNew ? this.referentiel.titre : '', [
Validators.required,
]),
description: new FormControl(!this.isNew ? this.referentiel.description : '', [
Validators.required,
])
});
}
}
The variable this.referentiel return me an undefined so I can't bind my Form whith existing value because of that...
Any suggestions ?