ng-holder icon indicating copy to clipboard operation
ng-holder copied to clipboard

Dynamically changing img based on "text"

Open vikasprogrammer opened this issue 9 years ago • 2 comments

Is it possible to dynamically change img based on the text set by controller?

vikasprogrammer avatar Dec 13 '15 14:12 vikasprogrammer

Not the way it is currently written. But something like this could work assuming you are using data-src:

module.directive('holder', [
  function() {
    return {
      link: function(scope, element, attrs) {
        if(attrs.holder) {
          attrs.$set('data-src', attrs.holder);
        }
        scope.$watch('data-src') function() {
          Holder.run({images:element[0]});
        });
      }
    };
  }]);

I kinda like how the current implementation doesn't produce a watcher though. I'd like to find a way to have both before committing this to the repo. Thoughts?

joshvillbrandt avatar Dec 14 '15 17:12 joshvillbrandt

You are right, having a watcher depends upon the implementation and may not be suitable for every use case. Can we provide a configuration variable or a directive to enable watching, like :

<img holder data-src="" holder-watch>

vikasprogrammer avatar Dec 15 '15 05:12 vikasprogrammer