-
Notifications
You must be signed in to change notification settings - Fork 27.5k
angular.element.scope() returns undefined #9515
Comments
Can you provide a plnkr reproduction of the issue please? |
I have the same issue in my own project, but can't reproduce it using plnkr. scope() returns undefined on any element. Using JQLite or JQuery 2.1.1 does the same. AngularJS 1.3.1. |
Try this:
|
are you disabling debug info in your project @VictorQueiroz? |
@caitp You've found it. Enabling debug info back is a good workaround for this issue. |
😄 😄 😄 |
This adds the first plugin: sortable. Note that degubInfoEnabled(false) is commented because of issue angular/angular.js#9515
Sorry guys for not reacting for a while. The issue is somehow related to jqCache, or more specifically to the way how expandoId is created. In older RCs, the id was created like this: |
Oh wow thanks @caitp that was driving me mad ! Edit: my bad, it's already in the doc
|
Is there a way around this; having debugInfoEnabled(false), but still being able to access the scope of an element? |
If you want to enable debug information temporarily (e.g. for debugging an issue on a live production app) you can use |
I think that @gkalpak clarified things here! |
Why closing ? Finding a workaround doen't means the issue is fixed, scope() should return the attached scope regardless the debug mode. If not possible, it should be be cleary documented in angular.element#scope() doc. |
@Toilal I've closed it since it is documented already as mentioned in the previous comments of this thread. But if you believe that it should documented in other places as well a PR would be much appreciated! |
I can't because i'm not sure witch methods from angular.element won't work when disabling debug. scope() for sure because i've tried it, but how about the others, like controller(), injector() ... |
After testing, it only impacts scope() and isolateScope(). I'll document those and make a PR. But is there any way to retrieve the scope from a DOM element while having debug info disabled ? |
@Toilal - not really - scope info was removed as exposing it has perf impact - this is why it is hidden behind a debug flag. |
But it wouldn't be that hard to write a directive that could do that and put it on the elements that you need to check |
Thanks @pkozlowski-opensource. I've added a small sentence on scope() and isolateScope() in docs, because it takes me some times to figure out why those methods didn't work in my application. |
@ocombe That's what i'll do, because i'm writing a UI component and can't rely on scope/isolateScope as end developer could disable debug info (as it's recommended). |
element.scope() may be undefined when wiring in the info gesture, so check for that. That this is sometimes undefined appears to be a consequence of changes to mct-representation, but which changes influence this are unclear. In any event, it appears that this cannot be relied-upon per angular/angular.js#9515
I've used the following snipet (not recommended) method in the
|
Is there any way to check if debugInfo has been disabled or any flag for it? |
From within the app, you can use |
@gkalpak I just want to check if debug info is enabled or not. Somewhat like this.
|
@hemkaran , it is still not obvious where you want to check it from. I assume from inside your app. |
Sorry I don't use Angular 1 anymore, and I never had to write such a directive (because I only needed this info in dev mode) |
I did the following. We'll see if my teammates will let it through the review :) function exposeScope() {
return {
restrict: 'A',
link: function(scope, element) {
element[0].APPNAME = {
getScope: function() {
return scope;
}
};
}
};
} |
You can also set $isolateScope to the same if you need it. |
angular.element.scope() is undefined when the application is loaded in iframe by changing the iframe src attribute.
The following code should return reference to scope but returns undefined:
The code above is executed in the onclick handler after the document is loaded and angular has finished bootstrap:
The issue manifests itself only when the document is loaded in the iframe by modifying its src attribute.
Tested with 1.3.0-rc.5, without jquery.
The text was updated successfully, but these errors were encountered: