2016-11-07 32 views
0

Im与Anuglar有问题。 ng-bind一旦它的值被用户输入改变,它就不会更新textarea。Angular - 在用户输入后不能更新textarea

注意:使用ng-bind代替ng模型的原因是我需要ng-bind-html作为输入在html中使用ngSanitize进行sanatized。

演示: http://jsfiddle.net/Lvc0u55v/11682/

这里是如何看什么即时通讯谈论:在下拉菜单和文本区域选择anyvalue被更新。但是选择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

是msg_templates''v.title乞伏故意或者它想使用'comm_templates'?你应该使用'