[英]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.