【问题标题】:Fetch and display table data in angular and laravel在 Angular 和 laravel 中获取和显示表格数据
【发布时间】:2022-01-20 22:23:43
【问题描述】:

我正在尝试以角表代码显示从 laravel api 获取的数据:

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

角码:

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

这不显示任何数据

我必须使用

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

推送所有数据。如何推送所有数组数据。

并使用循环显示数据

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

【问题讨论】:

    标签: angular laravel laravel-5


    【解决方案1】:

    您当前正在将一个数组推入一个数组。 要获得您想要的结果,您只需将结果数组分配给问题数组:

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

    【讨论】:

    • 感谢您的回答,现在收到此错误The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
    • 问题是如何定义的?它们是特定的数据类型吗?如果您确实将 this.http.post() 更改为 this.http.post(),否则您可以使用 this.http.post()
    • 我已经定义为数组questions = [];
    • 查看我的编辑。您也可以将问题定义为 questions:any = []
    猜你喜欢
    • 2020-03-06
    • 2019-06-19
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多