我和Anuglar有问题。一旦用户输入改变了值,ng-bind
就不会更新textarea。
注意:我使用ng-bind而不是ng-model的原因是我需要ng-bind-html
,因为输入是使用ngSanitize
进行html sanatized。
演示: http://jsfiddle.net/Lvc0u55v/11682/
以下是如何看待我正在谈论的内容:从下拉列表中选择任何值,并更新textarea。但是选择New Value
并在textarea中添加一些文本。然后将选择框更改为任何值,textarea永远不会再次更改!
代码:
[SCRIPT]
$scope.msg_templates = []; //array of {id, title, msg} filled with required stuff
$scope.msg_templates[0] = {id:'0', title:'{New Value}', msg:''}; //first item is to enter new value
$scope.msg_templates[1] = {id:'1', title:'TTT', msg:'TTT'};
$scope.msg_templates[2] = {id:'2', title:'XXX', msg:'XXX'};
.
.
//set default value
$scope.msg_sel = '';
$scope.msg_field = '';
//change msg function
$scope.change_msg_sel = function()
{
if($scope.msg_sel==null){
$scope.msg_field = '';
return false;
}
$scope.msg_field = $scope.msg_sel.msg;
};
[HTML]
<select ng-model="msg_sel" ng-change="change_msg_sel()" ng-options="v.title for v in msg_templates">
<option value="">Please Select -</option>
</select>
<textarea ng-bind-html="msg_field"></textarea>
答案 0 :(得分:2)
自己解决问题,只需使用 good-ol-always-working-vintage-JS 手动覆盖Element {
white-space: nowrap;
}
内的字段值!
$scope.change_msg_sel
(document.getElementById('msg_field').value=$scope.msg_field;
!!)