我試圖在角表代碼中顯示從 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">
uj5u.com熱心網友回復:
您當前正在將一個陣列推送到一個陣列中。要獲得您想要的結果,您只需將結果陣列分配給問題陣列:
...subscribe(result => {this.questions = result})
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/384978.html
