I'm trying to $watch
my element's width inside a directive:
appDrct.directive('setWidth', function($interval) {
return {
require: '?ngModel',
link: function($scope, $elm, attr, ngModel) {
$scope.$watch($elm.parent().width(), function() {
console.log('Width changed');
});
}
}
})
But it doesn't work...I know for a fact that my width changes (I tried with $interval
to display the width and it changes)
Here's how you do it, you need to $watch
the function expression:
$scope.$watch(function () {
return $element[0].style.width;
}, function(newVal, oldVal) {
console.log('Width changed');
});
Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With