角度指示手表高度

Angular directive watch height

本文关键字:高度 手表 指示      更新时间:2023-09-26

问题已经被提出,但无法正常工作。

在我的指令中,如果元素的高度上升,则使用这段代码是有效的,但当元素的高度下降时则不起作用。

$scope.$watch(function () {
        return element[0].offsetHeight;
    },
    function (value) {
        console.log(value);
    }
);

edit:高度变化是因为在父控制器中我使用ng重复

工作演示

确保在更改高度时调用作用域摘要

 $interval(function(){
    height += 10;
    ele.css({height: height + 'px'})
 }, 1000)