2016-11-07 57 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'?你應該使用'