首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不使用角7的ngComponentOutlet或ndcDynamicComponent

不使用角7的ngComponentOutlet或ndcDynamicComponent
EN

Stack Overflow用户
提问于 2021-08-20 20:16:44
回答 1查看 224关注 0票数 0

你好,我真的很困惑,为什么它不工作,它很简单,但我还是有问题。我得到空白输出&我的组件有一些数据,如果我直接用它的选择器调用它,这些数据就会更新。

这是我的密码。

app.module.ts

代码语言:javascript
复制
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeatSealComponent } from './heat-seal/heat-seal.component';
import { PrinterComponent } from './printer/printer.component';
import { DynamicModule } from 'ng-dynamic-component';

@NgModule({
  declarations: [
    AppComponent,
    HeatSealComponent,
    PrinterComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    [DynamicModule],
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.html

代码语言:javascript
复制
<ng-container *ngComponentOutlet="dumm"></ng-container>
<ndc-dynamic [ndcDynamicComponent]="dumm"></ndc-dynamic>

app.component.ts

代码语言:javascript
复制
import { element } from 'protractor';
import { Component, OnInit } from '@angular/core';
import { HeatSealComponent } from './heat-seal/heat-seal.component';
import { PrinterComponent } from './printer/printer.component';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent implements OnInit{
  title = 'dynamic-loading';
  dumm = HeatSealComponent;

  ngOnInit() {

    // this.myContent = {name:'nope'};
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-03 15:51:35

解决方案是在EntryComponents中的my模块文件中声明组件。

代码语言:javascript
复制
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeatSealComponent } from './heat-seal/heat-seal.component';
import { PrinterComponent } from './printer/printer.component';
import { DynamicModule } from 'ng-dynamic-component';

@NgModule({
  declarations: [
    AppComponent,
    HeatSealComponent,
    PrinterComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    [DynamicModule],
  ],
  providers: [],
  bootstrap: [AppComponent],
  entryComponents: [HeatSealComponent, PrinterComponent], // ADD THIS
})
export class AppModule { }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68867657

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档