【问题标题】:angularjs load data from mysql then dispaly by anglularjsangularjs 从 mysql 加载数据然后由 angularjs 显示
【发布时间】: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吗?能解释一下吗

标签: php angularjs json


【解决方案1】:

一个简单的例子

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;
                        });
                 };
             });

【讨论】:

    猜你喜欢
    • 2016-09-12
    • 2013-04-16
    • 2016-03-23
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多