-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ng1): grab injector from app. #451
- Loading branch information
Showing
1 changed file
with
1 addition
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mlynch I don't think this will ever work, see: http://codepen.io/anon/pen/QKWOPK?editors=1011
2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a test suite here: #523 with the improved (not leaking $q onto the
IonicNative
) ng1 promises fix I proposed in the other issue, you're welcome to check out the branch and hack about to try and find a better solution, currently using therun
block is the only way I can find though 😞 (I had a look to see how the ionic-cloud client works and that uses the run block too: https://github.com/driftyco/ionic-cloud/blob/master/src/angular.js#L54)2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, works fine for me on angular 1.5.3, I wonder what the discrepancy is about.
2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's really weird, it's not working in this codepen (check the console): http://codepen.io/anon/pen/QKWOPK?editors=1011 or in unit tests :/
2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I see, it starts to work once you're inside of a controller. Let me re-evaluate. I still think there's a cleaner way to do this
2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More generally: it works after a
$timeout
, doesn't have anything to do with controller2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird how it only works after a timeout :/ Better to use
document.querySelector('[ng-app]')
than document.body in case theng-app
isn't on the body tag, other than that I think it does the trick! I'll update my PR with it now 😄2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about injecting
$rootElement
and using it like this:$rootElement.injector().get('$q')
That should work and is cleaner. Thoughts?
2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you get the
$rootElement
from outside of angular though?2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, good call :D
So, the issue with
[ng-app]
is that it won't work if the user bootstrapped manually. I believe (and my tests have shown this), that usingdocument.body
will work even if they bootstrapped with the<html>
node2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document.body will work if ng-app is on the html or body tag, if it's somewhere inside the body tag it doesn't though. Same goes for if they bootstrap the app on an element that isn't the body or html tag :/
2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, okay. This might be a case where we have to just rely on ng-app. I'm fine with that for now.
2dc68a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR sent #524 with the changes we discussed, I added a console warning as well for the edge cases where this might not work, so at least the user will be aware 😄