I have an angular directive to change image source according to screen size.it is working fine with static content but it is not working with dynamic data come from $http request.
My directive
app.directive("changeOnScreenResize", ["$window", function($window) {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
$window.onresize = function() {
changeImage();
scope.$apply();
}
changeImage();
function changeImage() {
scope.screenWidth = $window.innerWidth;
if(scope.screenWidth <= 600) {
elem.attr('src', attrs.small);
console.log(attrs.small);
}
else {
elem.attr('src', attrs.big);
}
}
}
};
}]);
Dynamic Data Call from $http
<div ng-repeat="slideContent in vm.slides track by $index" >
<div ng-bind-html="vm.getHtml(slideContent)"></div>
</div>
Static Data which is same as data get from $http request and directive is working fine in this case.
<img change-on-screen-resize src="abc.jpg" small="xyz.jpg" big="abcd.jpg" >
vm.slideslook like? Why do you have to getHTMLthrough a function?