[英]How can I watch ngSrc of an img element and get the new width and height inside of my custom directive?
[英]$watch for element width inside directive
我正试图在指令中$watch
元素的宽度:
appDrct.directive('setWidth', function($interval) {
return {
require: '?ngModel',
link: function($scope, $elm, attr, ngModel) {
$scope.$watch($elm.parent().width(), function() {
console.log('Width changed');
});
}
}
})
但它不起作用......我知道我的宽度发生了变化(我尝试用$interval
来显示宽度并且它会发生变化)
这是你如何做到的,你需要$watch
函数表达式:
$scope.$watch(function () {
return $element[0].style.width;
}, function(newVal, oldVal) {
console.log('Width changed');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.