Javascript &引用;选择器应用程序根目录与任何元素都不匹配;将Angular 5应用程序动态注入iframe时

Javascript &引用;选择器应用程序根目录与任何元素都不匹配;将Angular 5应用程序动态注入iframe时,javascript,angular,iframe,Javascript,Angular,Iframe,我们有一个独特的情况,我们手动将iframe注入到包含Angular 5应用程序的页面中。用户可以将此Javascript文件包含到任何HTML页面上,而HTML页面又会注入iframe。如果我硬编码,我不会得到错误。但是,如果使用以下代码注入iframe,则会出现以下错误。Angular应用程序似乎在iframe被注入之前就在寻找app根元素(如果我在injectIframe()方法中放置了一个断点,那么在触发断点之前就会出现错误) 有没有一种方法可以在iframe完成加载后手动引导应用程序或

我们有一个独特的情况,我们手动将iframe注入到包含Angular 5应用程序的页面中。用户可以将此Javascript文件包含到任何HTML页面上,而HTML页面又会注入iframe。如果我硬编码,我不会得到错误。但是,如果使用以下代码注入iframe,则会出现以下错误。Angular应用程序似乎在iframe被注入之前就在寻找app根元素(如果我在injectIframe()方法中放置了一个断点,那么在触发断点之前就会出现错误)

有没有一种方法可以在iframe完成加载后手动引导应用程序或其他东西,这样在调用injectIframe之前就不会寻找它了

以下是注入iframe的Javascript(包含在父窗口中的脚本中):

app.module.ts:

const appRoutes: Routes = [
  {
    path: '',
    redirectTo: 'home-page',
    pathMatch: 'full'
  }
];

/*
 * Main module for the app that boostraps everything.
 */
@NgModule({
  imports: [
    BrowserModule,
    HttpClientModule,
    FormsModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    RouterModule.forRoot(
      appRoutes
    )
  ],
  declarations: [
    RootComponent,
    AppComponent
  ],
  providers: [
    AppGuard,
    WindowRefService,
    EventsService,
    MessageService,
    ApmSharedService,
    {
        provide: HTTP_INTERCEPTORS,
        useClass: AppInterceptor,
        multi: true,
    },
    {provide: APP_BASE_HREF, useValue : '/' }
  ],
  bootstrap: [RootComponent]
})

export class AppModule { }
@Component({
    selector: 'app-root',
    template: '<router-outlet></router-outlet>'
})

export class RootComponent {}
@Component({
    selector: 'app-comp',
    templateUrl: './app.component.html'
})

export class AppComponent implements AfterViewInit {

  ...... [some stuff] .....

}
root.component.ts:

const appRoutes: Routes = [
  {
    path: '',
    redirectTo: 'home-page',
    pathMatch: 'full'
  }
];

/*
 * Main module for the app that boostraps everything.
 */
@NgModule({
  imports: [
    BrowserModule,
    HttpClientModule,
    FormsModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    RouterModule.forRoot(
      appRoutes
    )
  ],
  declarations: [
    RootComponent,
    AppComponent
  ],
  providers: [
    AppGuard,
    WindowRefService,
    EventsService,
    MessageService,
    ApmSharedService,
    {
        provide: HTTP_INTERCEPTORS,
        useClass: AppInterceptor,
        multi: true,
    },
    {provide: APP_BASE_HREF, useValue : '/' }
  ],
  bootstrap: [RootComponent]
})

export class AppModule { }
@Component({
    selector: 'app-root',
    template: '<router-outlet></router-outlet>'
})

export class RootComponent {}
@Component({
    selector: 'app-comp',
    templateUrl: './app.component.html'
})

export class AppComponent implements AfterViewInit {

  ...... [some stuff] .....

}

你能给我们看一下注入角度组件的html/js代码吗?