Home > other >  Fetch and display table data in angular and laravel
Fetch and display table data in angular and laravel

Time:12-18

I'm trying to display data fetched from laravel api in angular table code is :

public function fetchQuestions(Request $request)
{  
  $questions = Questions::where('status',$request->status)->get();
  return response()->json($questions, 200);
}

angular code:

 questions = [];
  ...
  this.http.post(this.baseUrl 'api/auth/question', formData).subscribe(result  => {
  this.questions.push(result);

This does not display any data

i have to use

  this.questions.push(result[0]);
  this.questions.push(result[1]);
  ..
  ..
  this.questions.push(result[n]);

to push all the data. How can i push all array data.

and display data using loop

<ng-container *ngFor="let img of questions; let i=index">

CodePudding user response:

You are currently pushing an array into an array. To get the result you want you should just assign the result array to the questions array:

...subscribe(result => {this.questions = result})
  • Related