Ngx-bootstrap: EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot read property 'parentInjector' of undefined

Created on 24 Jun 2016  路  10Comments  路  Source: valor-software/ngx-bootstrap

Don't forget to add hack to your application root component (why?)

import {Component, ViewContainerRef} from '@angular/core';

@Component({selector:'app-root'})
class AppRoot {
public constructor(viewContainerRef:ViewContainerRef) {
// You need this small hack in order to catch application root view container ref
this.viewContainerRef = viewContainerRef;
}
}

what is mean ?
app-root and AppRoot

Most helpful comment

Basically the modal needs access to the AppRoot so it can do the fancy fading/overlay. To achieve this you need to create an viewContainerRef class member in you AppRoot component:

export class AppComponent implements OnInit {

  viewContainerRef: ViewContainerRef;

  constructor(viewContainerRef:ViewContainerRef) {
    this.viewContainerRef = viewContainerRef;
  }

All 10 comments

ng2-bootstrap doc is too low
i can't undersdan

error TS2339: Property 'viewContainerRef' does not exist on type 'AppRoot'.

do you provide complete example

Basically the modal needs access to the AppRoot so it can do the fancy fading/overlay. To achieve this you need to create an viewContainerRef class member in you AppRoot component:

export class AppComponent implements OnInit {

  viewContainerRef: ViewContainerRef;

  constructor(viewContainerRef:ViewContainerRef) {
    this.viewContainerRef = viewContainerRef;
  }

@moloch-- thanks for help, that's correct

worked for me! I was adding the ViewcontainerRef hack to the component instead of the root app.
leaving the comment just in case someone else commit the same mistake than me.

Can this be added to the docs? It took me quite a while to figure this out.

@yesman85 it is in doc http://valor-software.com/ng2-bootstrap/#/modals
Prior rc.4 you didn't need it until you use modals,
Now you do

Yeah I read that part, but it was missing this line:
viewContainerRef: ViewContainerRef;

it threw me off guard as TS wouldn't compile without it.

This doesn't appear to fix the issue when using nested routers. Has anyone else experienced this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

srjkrl20011991 picture srjkrl20011991  路  3Comments

KimBum picture KimBum  路  3Comments

haisaco picture haisaco  路  3Comments

juanitavollmering picture juanitavollmering  路  3Comments

tuoitrexuquang picture tuoitrexuquang  路  3Comments