I'm following this Tutorial for my Ionic app. This using http Module.But now angular 4+ has httpClient. I have done some changes according to that. Now app is working fine until I start. When I restart the app it shows the error
Property 'questions' does not exist on type 'Object'.
but again when I hit ctrl+s and save changes error is disappeared. How can I fix this??
Json is
{
"questions": [
{
"flashCardFront": "<img src='assets/imgs/helicopter.png' />",
"flashCardBack": "Helicopter",
"flashCardFlipped": false,
"questionText": "What is this?",
"answers": [
{"answer": "Helicopter", "correct": true, "selected": false},
{"answer": "Plane", "correct": false, "selected": false},
{"answer": "Truck", "correct": false, "selected": false}
]
},
{
"flashCardFront": "<img src='assets/imgs/plane.png' />",
"flashCardBack": "Plane",
"flashCardFlipped": false,
"questionText": "What is this?",
"answers": [
{"answer": "Helicopter", "correct": false, "selected": false},
{"answer": "Plane", "correct": true, "selected": false},
{"answer": "Truck", "correct": false, "selected": false}
]
},
{
"flashCardFront": "<img src='assets/imgs/truck.png' />",
"flashCardBack": "Truck",
"flashCardFlipped": false,
"questionText": "What is this?",
"answers": [
{"answer": "Helicopter", "correct": false, "selected": false},
{"answer": "Plane", "correct": false, "selected": false},
{"answer": "Truck", "correct": true, "selected": false}
]
}
]
}
Here is my code in provider using httpClient
load() {
if(this.data) {
return Promise.resolve(this.data);
}
return new Promise(resolve => {
this.http.get('assets/data/questions.json').subscribe(data => {
this.data = data.questions; //error here
resolve(this.data);
});
});
}