Angular JS:无法将修改后的文本区域返回给JavaScript

时间:2018-01-20 20:53:05

标签: javascript jquery html angularjs

HTML:

<div class="col-md-12 col-lg-12">
    <div class="panel with-nav-tabs panel-default">
        <div class="panel-heading">
            <ul class="nav nav-tabs">
                <li class="active"><a href="#tab1default" data-toggle="tab">Apex Editor</a></li>
            </ul>
        </div>
        <div class="panel-body">
            <div class="btn-group-vertical">
                <button type="button" class="btn btn-primary" id="editBtn">Edit</button>
                </button>
            </div>
            <div class="tab-content" align="left">

                <div>{{apexClassWrapper.name}}</div>
                <pre class="prettyprint">
                    <code class="language-java">
                        <textarea ng-change>{{apexClassWrapper.body}}</textarea>
                    </code>
                </pre>
            </div>
            <button type="button" class="btn btn-primary" id="saveBtn" ng-click="postdata(apexClassWrapper)">Save</button>
        </div>
    </div>
</div>

JavaScript:

function OrderFormController($scope, $http) {

    $http.get("http://localhost:8989/getApexBody").then(function (response) {
        $scope.apexClassWrapper = response.data;
    });


    $scope.postdata = function (apexClassWrapper) {
        console.log(apexClassWrapper);

        var dataObj = {
            name: apexClassWrapper.name,
            body: apexClassWrapper.body,
            id: apexClassWrapper.id
        };

        $http.post("http://localhost:8989/modifyApexBody", dataObj)
            .success(function (data) {
                $scope.message = data;
            })
            .error(function (data) {
                alert("failure message: " + JSON.stringify({data: data}));
            });

    };

};

当我单击“保存”按钮时,我无法从<textArea>标记中获取修改后的数据,它为我提供了范围数据。当我单击“保存”按钮时,如何将修改后的数据从TextArea从Html传递到我的JavaScript文件?

第二个问题: 我正在使用&#34; prettyprint&#34;但它仍然不起作用,我也包括这些文件:

<script src="../js/prettify.js"></script>
<script src="../js/run_prettify.js"></script>
<script src="../js/lang-basic.js"></script>
<link href="../css/prettify.css" rel="stylesheet"/>

文本区域仍显示正常的黑色文字。

1 个答案:

答案 0 :(得分:1)

在标签上设置NgModel

<textarea ng-model="apexClassWrapper.body"></textarea>