Closed pocesar closed 10 years ago
This is covered under breaking changes, see commit https://github.com/angular/angular.js/commit/909cabd36d779598763cc358979ecd85bb40d4d7
The isolate scope is only accessible through the template of the isolate scope's directive, or by manually grabbing the isolate scope via the jqLite isolateScope() method.
I don't know if I'm missing something, but this seems like a pretty bit setback. Is there a way to bind the isolate scope to a directive that's rendered without template
?
If your directive definition has a scope
property whose value is an object, the directive gets an isolate scope.
The bindings from the isolate scope are never used from other things (like children of the isolate scope directive that weren't created by the isolate scope directives template).
I know that it's convenient to use isolate scope bindings to generate your watches and stuff, but you don't strictly speaking "need" to.
@IgorMinar what would you think about letting people use isolate scope bindings for not-isolate scopes, though? We could extend the directive API even further with like a "notIsolate: true"
property or something.
It gives me a headache just thinking about how crazy the directive API is at this point, but you could consider it an inconvenience, and I think people are largely using isolate scopes in many cases for the convenience of the compiler setting up watches for them.
That's also true, it seems like setting up scope bindings isn't necessarily intuitively tied with isolate scopes (that's basically the use case I have... I'm trying to pass in two separate variables as a scope variable, and an isolate scope is the only option it seems).
However, it also seems unintuitive that you couldn't bind an isolate scope without a template option, right?
Isolate scopes are really meant to be used for components which are reusable, and should not be closely tied to a given scope (you can't assume that they're instantiated under a given controller, etc).
It would be convenient to be able to set up those bindings for child scopes too, but it would still make the directive API even crazier than it already is, so I dunno.
Yeah, my use case is in fact a component that is reusable, it just doesn't have a template/markup. Quite a few of reusable components don't have a need for more markup, especially things like attribute directives, but currently if you want to isolate the scope and want a method attached to a click handler like @pocesar mentioned above, I'm assuming you would just have to set up that listener in the link/controller function manually? (which obviously isn't ideal)
Version 1.2.1: http://jsfiddle.net/JNga3/9/ doesn't work anymore Version 1.2.0RC2: http://jsfiddle.net/JNga3/7/ working as intended
the only way it can work is using at least
scope:true
. it also appear that not onlyng-click
is affected, but everything that relies on the isolated scope values.