Error with the constructor and services

0
constructor(private pdpService : PdpService, private tostr : ToastrService) { }

ngOnInit() {
    this.pdpService.getData();
    this.resetForm();
}

What is inside the constructor does not show me the form with which I am working. If I take out what is inside, it appears. What am I doing wrong?

    
asked by Matias Cazas 06.03.2018 в 14:01
source

1 answer

0

If you are calling a service, this may be returning an observer. You must save it in a variable, to then access it.

let example: any;
constructor(private pdpService : PdpService, private tostr : ToastrService) { }

ngOnInit() {
            this.pdpService.getData().subscribe(data => this.example = data);
            this.resetForm();
        }
    
answered by 13.03.2018 в 15:55