我一直在与Laravel项目合作,我想实现angular js。应当以这种方式在页面加载时调用laravel函数,并将其结果显示在下拉选项(动态下拉列表)中。但是当我重复执行ng时,它会显示“未定义常量”错误。
这是我的代码
Laravel控制器
function getproducts(){
$data = DB::table('product as C')->select('C.*','F.name as cName','S.name as scName')->leftjoin('subcategory as S', 'S.id', '=', 'C.scId')->leftjoin('category as F', 'F.id', '=', 'S.cId')->get();
print_r(json_encode($data));
}
视图
<select class="form-control" ng-change="change()"><option ng-repeat="item in results ">{{item.id}}</option></select>
角度脚本
var app = angular.module('myApp', []);
app.controller('questionCtrl',['$scope', '$http', function($scope,$http) {
$scope.result =[];
$scope.getproducts = function (){
$http.get('getproducts').then(function (response) {
$scope.results = JSON.stringify(response.data);
},function (error) {
alert(error);
})
}
}]);
我遇到以下错误
"Use of undefined constant item - assumed 'item' (View:purchase.blade.php)"