joshvillbrandt/ng-holder

Dynamically changing img based on "text"

Opened this issue · 2 comments

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

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?

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>