html - ngComponentOutlet 或 ndcDynamicComponent 不适用于角度 7
问题描述
你好我真的很困惑为什么它不工作它很简单我仍然遇到问题。我得到空白输出,如果我直接用它的选择器调用它,我的组件有一些数据正在更新。
这是我的代码。
app.module.ts
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
<ng-container *ngComponentOutlet="dumm"></ng-container>
<ndc-dynamic [ndcDynamicComponent]="dumm"></ndc-dynamic>
app.component.ts
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'};
}
}
解决方案
解决方法是在我的模块文件的EntryComponents中声明组件。
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 { }
推荐阅读
- linux - Linux 特定部分的搜索和替换
- uwp - UWP - 单击其中的按钮时如何选择 ListViewItem
- google-chrome - 越过验证码 - Selenium
- google-analytics - 如何导入GA电商购物行为分析数据?
- csv - Jmeter with CSV file - approach thread group by row in CSV
- r - 按列总和过滤数据框
- r - 如何在 Shiny 中制作一个依赖于 checkboxGroupInput 来绘制特定值的条形图
- java - Apache Beam - 读取 JSON 和 Stream
- c# - 将 base64 字符串转换为 jpg/文件
- android - 带有图标和文本的按钮的填充可绘制