我有一个文本,看起来像这样:如何在指令中侦听textarea中的更改?
<textarea ng-controller="text" autoexpand id="tasks" ng-focus="uncheckAll()" ng-change="processText()" ng-model="tasks.tasks"></textarea>
的指令自动扩展是基于你写多少行添加行的文本区域。 (它在CSS NOWRAP设置)
//adding rows to the textarea based on the number of newlines.
directive('autoexpand', function($timeout){
function expand(element){
var count = element.val().split('\n').length+1;
element.attr('rows', count)
}
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, element){
//onload
$timeout(function(){
expand(element);
});
element.on('keydown', function(){
console.log('change')
expand(element)
});
}
}
}).
,当我通过写它更新textarea的,但有时,它是从模型更新这工作。我怎么能在这种情况下运行expand()
也(我试过element.on('change'...
,element.change(
和element.bind('change'
,但它似乎并没有在所有
它似乎没有触发,我是否需要添加范围或运行它在其他地方或东西? – Himmators