【发布时间】:2018-09-22 10:55:22
【问题描述】:
此代码无法使用 php 和 angularjs 显示来自 mysql 的数据
html代码-
<div class="container" ng-app="shoppingcart"
ng-controller="shoppingcartcontroller"> <div class="row " >
<div class="box col-md-3" style="margin-top: 20px;" ng-repeat="p in
products">
<div style="border: 1px solid #ccc; background-color: #f4f5f6">
<img src="/images/{{p.image}}.jpg" class="img img-responsive">
<h3>{{p.name}}</h3>
<h3>{{p.price}}</h3>
</div> </div>
</div> </div>
角码 -
<script >
var app=angular.module("shoppingcart",[]);
app.controller("shoppingcartcontroller",function($http,$scope){
$scope.loadproduct=function(){
$http.get("fetch.php").success(function(data){
$scope.products=data;
});
};
});
</script>
【问题讨论】:
-
你的 fetch.php 是做什么的?这将是真正的瓶颈。
-
能否把html代码说的详细一点。fetch.php返回的结果是什么?需要做ng-repeat吗?能解释一下吗