AngularJS隐藏字段不发送数据?

时间:2018-01-11 00:30:52

标签: javascript html angularjs

我遇到隐藏字段的问题,并从该字段将数据导入控制台。当我检查开发工具中的代码时,我可以看到隐藏字段的值是正确的。但是,在提交时,价值不会发生。隐藏字段的值是较大页面的子级。这是代码;

.controller('ReviewForm', ['$scope', '$http', function($scope, $http){


$scope.form = {

    cat1 : "",
    cat2 : "",
    cat3 : "",
    cat4 : "",
    cat5 : "",
    id: ""
};

$scope.submitForm = function() {


    console.log($scope.form)
}])

HTML

<input type="hidden" name="id" ng-model="form.id" ng-value="$parent.$parent.gid[0]['id']">

        {{ $parent.$parent.gid[0]['id'] }} // I see this in the browser, it is correct

// The rest of the form is checkboxes..
<div class="col-md-2 col-md-offset-1">
        <input class="input-radio" type="radio" id="control_01" name="cat1" ng-model="form.cat1" ng-value="1">
        <label class="label-radio" for="control_01">
            <h4>Very<br />Different!</h4>
            <p style="margin-top: -10px; color: purple"><i ng-repeat="i in [1]" class="fa fa-star"></i></p>
        </label>
    </div>

这些复选框值正确显示..

当我检查代码时,我可以看到它被正确呈现..

<input type="hidden" name="id" ng-model="form.id" ng-value="$parent.$parent.gid[0]['id']" 
autocomplete="off" 
class="ng-pristine ng-untouched ng-valid ng-empty" value="ChIJn8ORMaIIwYkRDjaLeuBXyN8"> 
// the value listed is correct.

但是,当我提交表单时..在控制台中我看到..

{cat1: 3, cat2: 3, cat3: 3, cat4: 3, cat5: 3, …}
cat1
: 3 // all of these values are correct?!
cat2
: 3
cat3
: 3
cat4
: 3
cat5
: 3
id
: "" // what gives??

我真的很感激任何帮助。这让我发疯了。

0 个答案:

没有答案