Need to use variable (defined inside the controller element of directive) in the template element.
angular.module('home').directive('mediaTile', function(){
return {
restrict: "AE",
replace: 'true',
scope: {
media: '=',
displayFilter: '='
},
controller: function($scope){
var vm = this;
vm.mediaImageActual = 'img/large-tiles.png'; }
},
controllerAs: 'vm',
template: '<div>' +
'<img preload-image ng-src="{{vm.mediaImageActual}}">' +
'</div>'
};
});
<div media-tile display-filter="view.displayFilter" media="dataList.lists[0]"></div>
ng-src is not getting the proper value i.e vm.mediaImageActual.
I have tried online solutions like this but unable to resolve the issue. Whats wrong ?
Try setting
bindToController: truein the directive.You can find more details here
If your are using angularJs1.6 or above, you can use
componentinstead of directive which has all these properties set by default