首页 > 解决方案 > 在 ng-repeat angularjs 中使用文本字段

问题描述

我在 angularjs 中有这样的代码和平:

<div ng-repeat="item in benchmarGeographyObj">

            <div style="padding-right: 60px;float:left;">
                <input readonly style="width: 100%;" type="text" id="unik"  ng-value="item.BEN_BENCHMARK_GEOGRAPHY" />

            </div>
  </div>

当我尝试在输入文本中添加 ng-model 时出现问题,ng-value 的值消失了,请问我该如何解决这个问题?

标签: angularjs

解决方案


var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.benchmarGeographyObj = [{'BEN_BENCHMARK_GEOGRAPHY': 1},{'BEN_BENCHMARK_GEOGRAPHY': 2}];
});
<!DOCTYPE html>
<html ng-app="plunker">

<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>
  <script>
    document.write('<base href="' + document.location + '" />');
  </script>
  <link rel="stylesheet" href="style.css" />
  <script data-require="angular.js@1.3.x" src="//code.angularjs.org/1.3.1/angular.js" data-semver="1.3.1"></script>
  <script src="app.js"></script>
</head>

<body ng-controller="MainCtrl">
  <div ng-repeat="item in benchmarGeographyObj">

            <div style="padding-right: 60px;float:left;">
                <input readonly style="width: 100%;" type="text" id="unik"  ng-model="item.BEN_BENCHMARK_GEOGRAPHY" />

            </div>
  </div>
</body>

</html>


推荐阅读