0

Context:

I'm applying a Lightbox effect on some DOM elements using an AngularJS directive named opensAsPopup.

Issue:

Some of these elements have dynamical content coming from a ng-repeat directive, and it seems that my opensAsPopup directive applies before the string interpolation.

Would that be possible to apply the lightbox effect after the string interpolation?


HTML:

<li>
  <a href="/path/to/{{entry.id}}" opens-as-popup>Link</a>
</li>

Script:

app.directive("opensAsPopup", [ ->
  restrict: "A"
  scope: {}
  replace: false
  transclude: false
  compile: (tElement, tAttrs) ->
    new lightbox(tElement.get(0))
])
1

1 Answer 1

4

You need to do it in the linking function. Scope is not applied till the link phase (which comes after the compile phase). Also do not create an isolated scope on the same element (removed scope: {}) as that would mean that you would need to set scope.entry.id within your link function. So:

app.directive("opensAsPopup", [ ->
  restrict: "A"
  replace: false
  transclude: false
  link: (scope,tElement, tAttrs) ->
    new lightbox(tElement.get(0))
])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.