angularjs从mysql加载数据,然后由anglularjs显示

时间:2018-09-22 10:55:22

标签: php angularjs json

此代码无法使用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>

1 个答案:

答案 0 :(得分:0)

一个简单的示例

HTML

<div ng-repeat="p in products">
 {{p.name}}
 {{p.price}}
</div>

JS

var app=angular.module("shoppingcart",[]); 

  app.controller("shoppingcartcontroller",function($http,$scope){

        $scope.loadproduct=function(){
                    $http.get("fetch.php").then(function(response){
                            $scope.products=response.data;
                        });
                 };
             });