Ngx-bootstrap: Cannot use Modal-hack in hybrid ng1/ng2 application

Created on 29 Sep 2016  路  12Comments  路  Source: valor-software/ngx-bootstrap

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?

Most helpful comment

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

All 12 comments

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

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

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?

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

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

Awesome thanks!

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

all possible hack points are empty for ngUpgrade

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

pss I am testing fix for it :)

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KimBum picture KimBum  路  3Comments

webdev48 picture webdev48  路  3Comments

tpiros picture tpiros  路  3Comments

ctrl-brk picture ctrl-brk  路  3Comments

phmello picture phmello  路  3Comments