dongliang1893 2016-11-02 10:15
浏览 33
已采纳

如何将AngularJS变量的值赋给PHP变量

After storing the value in PHP variable and trying to apply the condition check but I'm not able to do so.

<div ng-repeat="item in items track by $index">      
<?php
    $index= '{{$index}}';
    var_dump($index);

    if ($index==="1" || $index=="1") {
        echo $index;
        # code...
    }
?>
</div>

Do you have a solution?

  • 写回答

1条回答 默认 最新

  • duanpao4172 2016-11-02 10:31
    关注

    try to understand below code..

    db.php

    <?php
    
    include '../includes/config.php';
    
    switch ($_GET['action']) {
        case 'add_product' :
            add_product();
            break;
    
        case 'get_product' :
            get_product();
            break;
    }
    function get_product() {
        $qry = mysql_query('SELECT * from product');
        $data = array();
        while ($rows = mysql_fetch_array($qry)) {
            $data[] = array(
                "ng_id" => $rows['ID'],
                "ng_name" => $rows['Name'],
                "ng_desc" => $rows['Detail'],
                "ng_price" => $rows['Price'],
                "ng_quantity" => $rows['Quantity']
            );
        }
        print_r(json_encode($data));
        return json_encode($data);
    }
    

    app.js

    var app = angular.module('store', ["ngRoute"]);
    app.controller("mainController", function ($scope, $http) {
        $scope.get_product = function () {
            $http.get("db.php?action=get_product").success(function (data) {
    
                $scope.myData = data;
            }).error(function () {
                $scope.data = "error in fetching data";
            });
        };
    }
    

    index.php

    //if you want to use bootstrap div structure
        <div class="row" ng-repeat="x in myData">
          <div class="col-md-4">{{x.ng_id}}</div>
          <div class="col-md-4">{{x.ng_name}}</div>
          <div class="col-md-4">{{x.ng_desc}}</div>
        </div>
    
    //if you want to use table structure
        <table>
        <tbody data-ng-init="get_product();">
                       <tr data-ng-repeat="x in myData ">
                          <td>{{$index}}</td>
                          <td>{{ x.ng_name}}</td>
                          <td>{{ x.ng_desc}}</td>
                          <td>{{ x.ng_price}}</td>
                          <td>{{ x.ng_quantity}}</td>
                          <td>
                             <a href="" data-ng-click="edit_product(x.ng_id)">Edit</a> | 
                             <a href="" data-ng-click="delete_product(x.ng_id)" modal-backdrop="static">Delete</a>
                          </td>
                       </tr>
                    </tbody>
        </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求用matlab求解上述微分方程的程序代码
  • ¥15 请问各位,如何在Jetson nano主控板的Ubuntu系统中安装PyQt5
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致