Angularjs无法在ng模型加载后编辑文本区域
在用我的文本更新文本区域后,我似乎无法更新文本区域中的文本Angularjs无法在ng模型加载后编辑文本区域,angularjs,angularjs-directive,angularjs-scope,angularjs-ng-repeat,angular-ui,Angularjs,Angularjs Directive,Angularjs Scope,Angularjs Ng Repeat,Angular Ui,在用我的文本更新文本区域后,我似乎无法更新文本区域中的文本 $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].Sta
$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。详细信息。你把它弄得太复杂了。不要用如此复杂的函数检查或绑定数据 请检查我的更新。它会按照你的要求工作
<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();
@在文本区域内填充文本后键入A.B。。。您将无法键入。您绑定到的函数将返回相同的结果,而不管您在文本区域中输入什么。Angular正在用函数的结果覆盖文本更改。@user1620220我知道,对于这种情况,您的解决方案是什么?请在模型中添加另一个属性,并将其绑定到文本区域。更新d函数中的属性。@user1620220如何获取所选ID?