Note that there are some explanatory texts on larger screens.

plurals
  1. POAngular 1.2.0-rc.3 Directive Priority Change Issue
    primarykey
    data
    text
    <p>So I have this code example that uses Angular 1.2 RC2 and everything works fine, you click on the handle to toggle the display of the content and the controller and directive have seperate scopes as intended:</p> <p><a href="http://plnkr.co/edit/e3XAZuhSMAxmkWzKKM39?p=preview" rel="nofollow">http://plnkr.co/edit/e3XAZuhSMAxmkWzKKM39?p=preview</a></p> <p>Now I upgraded to Angular RC3 yesterday and now the functionality does not work as it stands in the plunker, I get the error the specific requires generic which is can't find. Going through the change log, I though this might have to do with this breaking change:</p> <p><code>$compile: due to 31f190d4, the order of postLink fn is now mirror opposite of the order in which corresponding preLinking and compile functions execute</code></p> <p>To fix this they either suggest converting the post linking to a pre linking (which I can do since my post linking needs access to the scope which is not available in the pre linking) or to decrease the priority of the directive. So this plunker does that and functionality does work:</p> <p><a href="http://plnkr.co/edit/arP3aruH8HEdiwFg6mWp?p=preview" rel="nofollow">http://plnkr.co/edit/arP3aruH8HEdiwFg6mWp?p=preview</a></p> <p>However there is a major issue and that is now because specific has a higher priority, the isolate scope that generic needs is no longer being created so now contentVisible is on the controller scope which is not good.</p> <p>Now I could just move the scope: {} from the generic directive to the specific directive however it should be possible to use the generic directive by itself and if I did it would attached to whatever scope it is part of and not its own (which would make it impossible to have multiple instance of this directive, which is way it needs its own scope).</p> <p>The only thing I can think of is to add a directive, called something like isoScope, make sure it has a very high priority, and have it define scope: {}. Then if I need to use generic by itself, I just have to make sure to also add the isoScope directive to make sure it has an isolate scope. Like this:</p> <p><a href="http://plnkr.co/edit/1NYHpUcPFWEbAzvkCeRH?p=preview" rel="nofollow">http://plnkr.co/edit/1NYHpUcPFWEbAzvkCeRH?p=preview</a></p> <p>Now I am hoping there is a better way to accomplish what I am looking for without the isolateScope directive. Am I missing a way of that this without that?</p> <p><strong>UPDATED EXAMPLE</strong></p> <p>So here is another plunker that includes hopefully better examples of what I am trying to convey (still has virtually no styles but should not be needed to get the point across):</p> <p><a href="http://plnkr.co/edit/KtRMa1c9giDrhi1Rqyho?p=preview" rel="nofollow">http://plnkr.co/edit/KtRMa1c9giDrhi1Rqyho?p=preview</a></p> <p>I have 3 directives:</p> <ul> <li>expander</li> <li>notification</li> <li>isolateScope</li> </ul> <p>The expander directive only adds functionality to be able expander and collapse content, nothing more. This functionality is something that should be able to be used alone or with another directive (which is why it has a controller).</p> <p>The notification directive is used to display notification however since we don't want to display the notifications all the time, we use it with the expander directive so that the user can toggle the display of the actually notifications (similar to how stackoverflow.com does it in the top left).</p> <p>While I imagine the expander would most likely be used with another directive it should be possible to use alone and that is where the isolateScope directive comes into play. Since the expander directive adds data to the scope and you may want to have multiple expanders on the same page, it needs to have an isolate scope in order to work. Now on a users profile page you have have data like developer key and address that you don't really need to display all the time so lets have the user control that. I have the isolate scope to be able to control both of those independently because without the isolate scope, both of them would be on the same scope and be controlled by the same instance on contentVisible.</p> <p>I just don't see anyway with how directives now run in 1.2.0 RC3 to be able to accomplish this without that isolateScope directive (though I would be happy to be proven wrong).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload