I am using an angular 1.5 component as defined below.
ngModule.component('devStudioImage', {
template: '<img id= "{{$ctrl.imageName}}" ng-src="{{$ctrl.source}}"/>',
controller: Controller,
bindings: {
imageName: '@',
imageHeight: '<',
imageWidth: '<',
imageDescription: '<?',
imageLoaded: '&'
}
});
I want to bind a load event as well for when the image has been loaded, but onload does not seem to work, and every other solution I seem to find involves making a directive.
Is there a way to capture that load event in this component, or if I have to use a directive, how can I use the same instance of the controller for my component?
Edit:
I ended up doing this. I think it's ugly, and feels...dirty, but it works.
I added a directive in addition to the component above, that applies to the parent scope a variable for an ng-show.
ngModule.directive('imageOnLoad', function() {
return {
restrict: 'A',
link: function (scope, element) {
element.bind('load', function() {
scope.$parent.$ctrl.loaded = true;
scope.$parent.$apply();
});
}
}
})