角度问题:如何使用post使用ng-model =“userObject.id”更新表单

时间:2017-02-21 22:33:51

标签: php angularjs

我正在尝试使用Angular js框架更新表单,并且ngmodel名称由点分隔 例如: - ng-model="userObject.id".

我将如何在php中发布userObject.id。检查以下语法

例如: - $categoryid = $request->categoryid;

我将如何在上面的语法

中发布userObject.id

是编写代码$categoryid = $request->userObject.id;的正确方法吗?

但是当我编写代码`$ categoryid = $ request-> userObject.id;浏览器出错了。

//controll

$scope.data = {};
    $scope.update = function() {
        var link = 'webServices/updateCategory.php';
        $http.post(link, { category_name: $scope.data.category_name, order_no: $scope.data.order_no }).then(function(res) {
            $scope.response = res.data;
            //  alert("Records updated successfully...");
            //$window.location.reload();
        });
    };
html code

<form class="form-horizontal">
                        <input type="hidden" ng-model="userObject.id">
                        <div class="form-group col-sm-4">
                            <label for="name" class="col-sm-2 control-label">Name </label>
                            <div class="col-sm-10">
                                <input type="test" class="form-control" id="name" placeholder="Name" ng-model="userObject.category_name" />
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label for="age" class="col-sm-2 control-label">Age</label>
                            <div class="col-sm-10">
                                <input type="test" class="form-control" id="age" placeholder="Age" ng-model="userObject.order_no" />
                            </div>
                        </div>
                        <input type="hidden" ng-model="$scope.objectIndex" class="ng-valid">
                        <div class="btn-group col-sm-2">
                            <button type="button" class="btn btn-primary btn" ng-click="update();"><i class="glyphicon glyphicon glyphicon-ok-circle"></i>Save</button>
                        </div>
                    </form>




<?
//php code
include("../include/connection.php");

$postdata = file_get_contents("php://input");
	if (isset($postdata)) {
		$request = json_decode($postdata);
        $id = $request->userObject.id;
        echo $id;
		$category_name = $request->userObject.category_name;
        echo $category_name;
        $order_no = '5';
            mysqli_query($con, "update category set `category_name`='".$category_name."', `order_no`='".$order_no."' where id='".$id."'");
			echo "Your account is created successfully";
	}
	else {
		echo "Not called properly with username parameter!";
	}
?>

谢谢你。

1 个答案:

答案 0 :(得分:0)

您可以使用$request->{'userObject.id'}来访问该变量。

Source