Say I have a directive :
<component> <img ng-src='{{something}}' /> </component>
defined as:
app.directive("component", function() { return { scope: {}, restrict: 'E', transclude: true, template: "<a href='' ng-click='MyService.doThings()' ng-transclude></a>" } });
Despite all my efforts, I do not understand how to perform two tasks:
- How do I access the internal path of the image source?
- How to pass this path to
MyService ? (think of a paint wrapper)
Update using solution:
app.directive("component", function(LightboxService) { return { restrict: 'E', transclude: true, replace: true, template: "<a href='' ng-click='lb()' ng-transclude></a>", link: function (scope, element, attrs) { scope.lb = function () { var src = $(element).find("img").attr("src"); LightboxService.show(src); } } } });
angularjs angularjs-scope angularjs-directive
Cranio
source share