小编CSa*_*tos的帖子

使用Angular 6 Web组件

我有以下问题.我有一个使用Angular 6和路由系统构建的应用程序.我想创建一个包含此应用程序的Web组件,并能够将其用作不同Web应用程序的一部分.我已按照本教程操作,并根据自己的需要对其进行了修改:https://codingthesmartway.com/angular-elements-a-practical-introduction-to-web-components-with-angular-6/

结果是屏幕上没有任何渲染,现在浏览器中存在错误Error: The selector "app-root" did not match any elements.

在浏览器源文件上,我可以确认包含我的Web组件的js文件已成功加载.

这是我有的:

在app.module.ts中

@NgModule({
  declarations: [
    AppComponent,
    VideoRoomComponent,
    DashboardComponent,
    StreamComponent,
    DialogNicknameComponent,
    ChatComponent,
    DialogExtensionComponent,
  ],
  imports: [
    FormsModule,
    ReactiveFormsModule,
    BrowserModule,
    BrowserAnimationsModule,
    MatButtonModule,
    MatCardModule,
    MatToolbarModule,
    MatIconModule,
    MatInputModule,
    MatFormFieldModule,
    MatDialogModule,
    MatTooltipModule,
    AppRoutingModule,
    HttpClientModule,
  ],
  entryComponents: [
    AppComponent,
    DialogNicknameComponent,
    DialogExtensionComponent,
  ],
  providers: [{provide: APP_BASE_HREF, useValue: '/'}, MyService],
  bootstrap: [AppComponent],
})
export class AppModule {
  constructor(private injector: Injector) {}

  ngDoBootstrap() {
    const el = createCustomElement(AppComponent, { injector: this.injector }); …
Run Code Online (Sandbox Code Playgroud)

elements angular angular6 angular-elements

1
推荐指数
1
解决办法
1459
查看次数

标签 统计

angular ×1

angular-elements ×1

angular6 ×1

elements ×1