-
Notifications
You must be signed in to change notification settings - Fork 25.3k
-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(upgrade): ng1 compiler throws because ng2.Injector controller is missing #6655
Comments
This also introduces an error thrown when `crHeader` directive is compiled by A1 and `<ui-view>` is used in the same template as the directive. Related issue: angular/angular#6655
If anyone wants to take a look at the commit that introduces the error, I've pushed the status to this branch here: thoughtram/classroom-app@9a7a538 |
Yes, ng2 requires parent ng2 Injector. The way we get it is by walking the DOM tree using the My guess would be that the ui-router is doing something which breaks this. If I had to guess, I would think that the ui-router compiles/links the DOM tree before it inserts it into the proper location in the DOM. The late linking causes the ngUpgrade to not find the injector. Can you try this with dev code (not minified so that we have propert stack traces). That way we can see what the ui-router is doing which is breaking this. |
Did you guys get a solution for this said problem? or there is a workaround for this? |
running into this issue as well |
Waiting for this fix desperately , could be a deal breaker for upgrading our app to ng2, unless we have a work around . |
@mhevery, is there a particular reason the ng2 injector is provided through AFAICT I was working on a plunkr to demonstrate this, but got blocked by #7525. |
The Injector in ng2 is hierarchical, which is why we walk the DOM to get it (At different points in the DOM there will be different ng2 injector.). Of the top of my head I don't see how this can be done in closure, but maybe you could give it a try? |
That does make sense. However, it seems like "ng2.InjectorController" only gets set once, on the root element. I guess it should be set by the UpgradeNg1ComponentAdapter? |
Hi! http://embed.plnkr.co/fPD0zUTr2s1MCgn66dDS/ See console log on plunker. |
Oups. Here's the right plunker link: https://embed.plnkr.co/n0KxZu/ |
Would anyone be willing to take on this issue and create a PR? |
I'll take a look. |
PR submitted. See #8684. |
YEAY! Thanks! |
#8684 is merged. can anyone test if the original UI router issue is fixed? (I just wrote unit tests) |
is this issue resolved? I submitted a PR a while ago that I believe is in RC2. |
resolved |
Hurray ! |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Stumbled upon something weird.
I have an Angular 1 app using the UI-Router. Which I started to upgrade using ngUpgrade. The default state configuration is as simple as:
First component I wanted to upgrade was
<cr-header>
. There's nothing special about it. So I did it and downgraded it a la:Running this in the browser throws the following error (while rendering works fine):
Angular 1 compiler basically complains because it can't find controller
ng2.Injector
as requested incrHeader
directive.It turns out that
downgradeNg2Component()
returns a directive that always requires anng2.Injector
controller as defined in: https://github.com/angular/angular/blob/master/modules/angular2/src/upgrade/upgrade_adapter.ts#L505I was confused why this errors is thrown, because I'm not upgrading the first time and it never happened before to me.
I
git blame
ed the file and that particular line of code and saw that it was introduced in 059e8faa, so this has been here since a long time, which brought me to the conclusion that there's something in my code base that causes the error.After inspecting the error I saw that
<ui-view class="ng-scope">
snippet in the stack trace. Even though I doubted that it could've anything to do with it, I remove<ui-view>
from the template to see if this error still occurs. It doesn'tSo apparently having a
<ui-view>
directive in a template where also a downgraded ng2 component is compiled, causes this error.The stack trace shows
updateView
call in ui-router, which can be inspected here: https://github.com/angular-ui/ui-router/blob/2d23875c211bf3169fbec5c24e05a351b6b969dc/release/angular-ui-router.js#L3959The text was updated successfully, but these errors were encountered: