如何用angularjs中的编辑数据替换输入字段?

时间:2017-03-25 04:17:48

标签: angularjs

我必须编辑输入字段。当我点击编辑按钮时,输入字段应该出现,当我在输入文本框中输入数据时,输入的数据必须在输入文本框的位置被替换。这是我的代码但我没有得到结果。我怎么能得到结果?

 $scope.options = function () {
        $scope.showBatch = !$scope.showBatch;
        $scope.val = $scope.batchNumber;
        
        document.getElementById("b1").innerHTML = $scope.val;

    }
<span id="b1" style="font-size:25px">Batch</span>
                        <span class="glyphicon glyphicon-pencil text-right" ng-click="options()"></span>
                        <input type="text" ng-show="showBatch" ng-model="batchNumber">

1 个答案:

答案 0 :(得分:0)

你在找这样的东西吗?

HTML

<span id="b1" ng-show="!showBatch" style="font-size:25px">{{batchNumber}}</span>
<input type="text" ng-show="showBatch" ng-model="batchNumber">
<span class="glyphicon glyphicon-pencil text-right" ng-click="options()"></span>

角度控制器

    $scope.batchNumber = "Batch";
    $scope.options = function () {
        $scope.showBatch = !$scope.showBatch;
        $scope.val = $scope.batchNumber;
    }