Skip to content
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

Cannot use Modal-hack in hybrid ng1/ng2 application #1056

Closed
danielnelin opened this issue Sep 29, 2016 · 12 comments
Closed

Cannot use Modal-hack in hybrid ng1/ng2 application #1056

danielnelin opened this issue Sep 29, 2016 · 12 comments
Assignees

Comments

@danielnelin
Copy link

We are using ng-upgrade while migrating our application from Angular 1->2.

We're trying to use Modals in our ng2 components, but the required hack does not work in this context, since there is no root-level angular 2 component at the moment.

Tried adding a downgraded AppRoot-component in in the main ng1-template, but it is never added to applicationRef.components so it fails with Cannot read property 'instance' of undefined in the ComponentsHelper

    ComponentsHelper.prototype.getRootViewContainerRef = function () {
        // The only way for now (by @mhevery)
        // https://github.com/angular/angular/issues/6446#issuecomment-173459525
        var appInstance = this.applicationRef.components[0].instance;
        if (!appInstance.viewContainerRef) {
            var appName = this.applicationRef.componentTypes[0].name;
            throw new Error("Missing 'viewContainerRef' declaration in " + appName + " constructor");
        }
        return appInstance.viewContainerRef;
    };

Is there any way around this for a hybrid app?

@valorkin valorkin self-assigned this Oct 3, 2016
@valorkin
Copy link
Member

valorkin commented Oct 3, 2016

I will try another hack today, so most probably I will drop this viewContainerRef root dep

@jhhoff02
Copy link

jhhoff02 commented Oct 3, 2016

+1 Please try another hack, I still get the error: Cannot read property 'parentInjector' of undefined

@danielnelin
Copy link
Author

Hi, thanks for looking at this.
Unfortunately, I don't think this solves our problem.
The applicationRef.components is still empty, so i just fails in a different way.
Our issue is that almost all of our application is still angular 1, including root-parts.
I still don't see how I am supposed to use the ng2-hack, and without the hack, I guess there will never be a viewContainerRef to refer to?

Maybe I'm just misunderstanding how I am supposed to get this working in hybrid-mode.
Did that work for you?

@valorkin
Copy link
Member

valorkin commented Oct 6, 2016

Give me a sample repo to reproduce, and I will drop a solution

@gios
Copy link

gios commented Oct 7, 2016

Hi, everyone. As you wish, I added the temporary repository for testing this defect. Please notify me, if you will have some results about it.
ng1-ng2-modal

@valorkin
Copy link
Member

valorkin commented Oct 7, 2016

Awesome thanks!

@valorkin
Copy link
Member

cloning, it is time to fix this once and for all ;)

@valorkin
Copy link
Member

all possible hack points are empty for ngUpgrade

@gios
Copy link

gios commented Oct 10, 2016

It's very bad news, do anyone have another ideas how to fix that and close the issue?

@valorkin
Copy link
Member

pss I am testing fix for it :)

@valorkin
Copy link
Member

this is how fix will looks like
https://github.com/gios/ng1-ng2-modal/pull/1/files

@danielnelin
Copy link
Author

Great!
We have verified that the latest version works in our hybrid-setup.
Thanks a lot for the fast resolution.

jtomaszewski pushed a commit to jtomaszewski/ng2-bootstrap that referenced this issue Oct 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants