3 ms·
The problem with isolate scope is that you need to pass in all the data through attributes. This is great if you want something reusable that won't collide. My
by RaphiePS 13y ago
The problem with isolate scope is that you need to pass in all the data through attributes. This is great if you want something reusable that won't collide. My rule of thumb is that if it's got its own template, it should be isolated.
However, this can really bite you in the butt. If you're doing something like
<div my-directive>{{foo}}</div>
where my-directive uses isolate scope, {{foo}} is broken. So I'd never use isolate scope for an attribute directive.
- gtremper 13y agoI thought you could do this since the scope of the transcluded part is a sibling to the isolate scope. "The advantage of transclusion is that the linking function receives a transclusion function which is pre-bound to the correct scope. In a typical setup the widget creates an isolate scope, but the transclusion is a sibling (rather than a child) of the isolate scope. This makes it possible for the widget to have private state, and the transclusion to be bound to the parent (pre-isolate) scope." http://docs.angularjs.org/guide/directive http://docs.angularjs.org/guide/directive
- RaphiePS 13y agoOoh, I didn't consider transclusion. For the example I used (an attribute directive), would I make its template literally <div ng-transclude></div>