![](/img/trans.png)
[英]Pass JSON data from AngularJS to Laravel Controller via POST
[英]Convey JSON from controller to AngularJS in Laravel
在Laravel中,我嘗試將MySQL中的數據作為JSON傳輸到AngularJS。 盡管我在此方面取得了成功,但我對如何利用AngularJS中的值感到困惑。 有什么幫助嗎?
檢查輸出數據(隱藏每個值)
控制者
public function index(){
return Response::json(Company::all());
}
AngularJS
var app = angular.module('companySearchApp', [], function($interpolateProvider) {
$interpolateProvider.startSymbol('<%');
$interpolateProvider.endSymbol('%>');
});
app.controller('CompanyCtrl', function($scope, $http){
$http.get('http://localhost:8000/json')
.then(function(response){
this.companies = response.data;
});
});
顯示
<div id="resultTable" align="center">
<h3>Search Result</h3>
<div ng-repeat="company in CompanyCtrl.companies">
<table border="1" style="margin-bottom:10px">
<tr>
<td colspan="3" class="col-xs-12"><% company.CompanyName %></td>
</tr>
<tr>
<td class="col-xs-4"><% company.City %></td>
<td class="col-xs-4"><% company.Province %></td>
<td class="col-xs-4"><% company.KeyWord %></td>
</tr>
<tr>
<td colspan="3"><% company.JobTitle %></td>
</tr>
<tr>
<td colspan="3"><% company.Link %></td>
</tr>
</table>
</div>
</div>
希望我能自己解決這個問題。 共有3個步驟。
$http.get('localhost:8000/json')
$http.get('/json')
將JSON設置為變量
在此之前this.companies = response.data;
在$scope.data = response.data;
ng-repeat
<div ng-repeat="company in CompanyCtrl.companies">
之前<div ng-repeat="company in CompanyCtrl.companies">
在<div ng-repeat="company in data">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.