I have the following code in the link function of my directive:
link: function (scope, element)
{
angular.element($window).bind('resize', scope.layout);
// angular.element($window).bind('resize', function()
// {
// scope.layout();
// });
scope.onImgLoad = function(e) {
scope.ih=e.target.naturalHeight;
scope.iw=e.target.naturalWidth;
//scope.layout();
};
scope.layout = function() {
// do some style stuff based on image and window size
}
}
When the window resize happens I get an error undefined is not a function (scope.layout) I also tried the commented piece of code but I got the same error. How can i call a function within the link scope in the resize event handler?
Update
The resize event was looking for a layout function in the parent directive. I solved it by giving my directive isolated scope.