PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, December 29, 2021

[FIXED] Fetch and display table data in angular and laravel

 December 29, 2021     angular, laravel, laravel-5     No comments   

Issue

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">

Solution

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})


Answered By - Raffael
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing