4

Wondering if someone can explain the current behavior.

I have one directive with isolate scope, call it dirA. I then put another directive on it, dirB. Expecting the second directive to get each scope that the isolate directive creates.

dirB gets the controller scope. Why would it not get the same isolate scope that dirA is creating for that element?

Thanks for any help. I don't really have any code for this, just curious. If anyone needs two little directives and some html to help visualize i will of course. thank you.

1 Answer 1

6

What you observe is correct and this behavior is by design.

When a directive requests an isolated scope, AngularJS creates a scope for that directive specifically, not for the element where the directive is declared on. In other words, the isolation is per-directive, not per-element. This makes coding reusable and standalone directives much easier than if one has to guard against improper usage of the isolated scope from other directives.

All other directives declared on the same element share the outer scope. (It's also worth noting that these directives can't even request their own scope, isolated or not. While this behavior is not guaranteed prior to 1.3 due to a bug, it is already fixed in 1.3.)

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.