我在td
标记(它位于tr
标记内)中有一个div
。这div
有需要$watch
元素的scrollHeight
自定义指令:
<tr ng-show="showRow">
<td>
<div my-custom-directive>My very long text</div>
</td>
</tr>
和指令:
appDrct.directive('myCustomDirective', [function() {
return {
restrict : 'A',
compile : function(elem, attr, linker) {
return function(scope, element, attributes) {
scope.$watch(element[0].scrollHeight, function(){
console.log('triggered');
})
}
}
}
}])
的showRow
通过ng-click
变量的变化。
的问题是,$watch
永远不会触发(除第一次),即使由于ng-show
的scrollHeight
变化(scrollHeight
等于0时ng-show
等于false
)。
我开始还以为是因为我不得不使用$scope.$apply
,但我不知道在哪里把它...
没关系... angularJS允许两个! – ncohen
没有。它不会允许 – simon
无论如何它不能解决我的问题... – ncohen