Hi everyone, please help me out here .
I am working on a quiz app, wherein I have used REST API to return the data from database. But as the data is too huge am unable to fetch it all in JSON format and hence am fetching it in the form of php array as shown below.
The problem is am really unaware of how to use this in the typescript file and loop thru in the controller. Am stuck with this since past 3-4 days.Any help or ideas will be appreciated, thanks in advance.
My sample array:
Array
(
[0] => Array
(
[SubjectID] => 16
[QuestionID] => 4358
[QuestionType] =>
[Question] => Which one is a wrong statement?
[Answer1] => some answer1.
[Answer2] => some answer2
[Answer3] => some answer3
[Answer4] => some answer4
[CorrectAnswer] => 4
[Hint] =>
[DiffLevel] => Medium
[Status] => Active
[AnsDescription] => some description.
)
[1] => Array
(
[SubjectID] => 16
[QuestionID] => 4359
[QuestionType] => SingleAnswer
[QuestionType] =>
[Question] => Which one is a wrong statement?
[Answer1] => some answer1.
[Answer2] => some answer2
[Answer3] => some answer3
[Answer4] => some answer4
[CorrectAnswer] => 4
[Hint] =>
[DiffLevel] => Medium
[Status] => Active
[AnsDescription] => some description
)
)
My controller/ typescript file:
Can I use it like below or should I assign it the “items” variable in some other way (Note: am assigning the data here directly to just test if its possible to loop through it and display in the html file).
Am a newbie to Ionic , so please excuse me if my question is something stupid.
import { Component } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;
_Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
items : any [];
constructor(public navCtrl: NavController) {
}
this.items = [Array
(
[0] => Array
(
[SubjectID] => 16
[QuestionID] => 4358
[QuestionType] =>
[Question] => Which one is a wrong statement?
[Answer1] => some answer1.
[Answer2] => some answer2
[Answer3] => some answer3
[Answer4] => some answer4
[CorrectAnswer] => 4
[Hint] =>
[DiffLevel] => Medium
[Status] => Active
[AnsDescription] => some description.
)
[1] => Array
(
[SubjectID] => 16
[QuestionID] => 4359
[QuestionType] => SingleAnswer
[QuestionType] =>
[Question] => Which one is a wrong statement?
[Answer1] => some answer1.
[Answer2] => some answer2
[Answer3] => some answer3
[Answer4] => some answer4
[CorrectAnswer] => 4
[Hint] =>
[DiffLevel] => Medium
[Status] => Active
[AnsDescription] => some description
)
)]
}