Siva Unique
Siva Unique

Reputation: 189

I need to get json using http when loading the app

I am not getting result when i am loading the app.

but i am getting the result when clicking the button

<button ion-item  (click)="goToDrivePage()">

but i need to load automatically when loading the app. any body help to get result?

Upvotes: 0

Views: 32

Answers (1)

umar
umar

Reputation: 910

You can do it in your app component constructor or ngInit function like

export class AppComponent implements OnInit {
    ngOnInit() {
            this.dataService.getData()
            .subscribe((data: any) => {
                this.data = data;
            });
        }
//OR
constructor() {
            this.dataService.getData()
            .subscribe((data: any) => {
                this.data = data;
            });
        }
}

Upvotes: 1

Related Questions