在ng-model加载后,Angularjs无法编辑textarea

时间:2015-03-24 19:57:39

标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat angular-ui

使用我的文本更新文本区域后,我似乎无法更新textarea中的文本。

$scope.desc = "";
$scope.d = function () {             
    for (var i = 0, len = $scope.stat.length; i < len; i++) {
        if ($scope.stat[i].Id == $scope.selectedId && $scope.statDate == $scope.stat[i].StatDate) {
            $scope.desc = $scope.stat[i].D;
            return $scope.stat[i].D;
            }
     }
     return "";
 };
$scope.des = function(){return $scope.d}

请访问此Plunker。 http://plnkr.co/edit/pVSiNrnAOY0A5v0iTmYQ?p=preview了解详情。

1 个答案:

答案 0 :(得分:0)

你太复杂了。不要检查或绑定具有如此复杂功能的数据。

只需在plunkr中查看我的更新即可。它将按您的要求工作。

 <select ng-model="selectedId"
   ng-options="ac.Id as ac.Name for ac in a"
   ng-init="selectedId = 1" ng-change="getTextValue()">
 </select>
 N
 <select ng-model="statDate" ng-options="time for time in times" ng-change="getTextValue()">
 </select>

 <textarea>{{textValue}}</textarea>

和js代码:

$scope.textValue;
$scope.getTextValue = function() {
  var selectedId = $scope.selectedId;
  var statDate = $scope.statDate;
  for (var i = 0, len = $scope.stat.length; i < len; i++) {
    console.log(i);
    if ($scope.stat[i].Id == selectedId && $scope.stat[i].StatDate == statDate) {
      $scope.textValue = $scope.stat[i].D;
      console.log("get value" + $scope.textValue);
      return;
    }
  }
  $scope.textValue = "";
};
// init text area value
$scope.getTextValue();