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>
是msg_templates''v.title乞伏故意或者它想使用'comm_templates'?你應該使用'
其實際的'msg_templates',忘記在這裏爲這個例子重命名它。 –
適合我[jsfiddle](http://jsfiddle.net/0yoxpd11/1/)。我的小提琴中唯一不同的是,我從'
>'中刪除了包裝'ngApp',因爲在另一箇中不能包含'ng-app'。你知道'$ scope.msg_templates [0]'有一個空白的'msg',所以當選擇什麼都不會顯示。 – user2718281