【问题标题】:1. If 'selector' is an Angular component, then verify that it is part of this module1.如果'selector'是一个Angular组件,那么验证它是这个模块的一部分
【发布时间】:2023-03-03 11:24:02
【问题描述】:

我无法注册我的组件。如果我设置

<app-actions-button></app-actions-button>

这很好。 但是如果我设置

<app-actions-button (send)="some($event)"></app-actions-button>

我遇到了错误:

src/app/test.component.html:162:1 中的错误 - 错误 NG8001:“app-actions-button”不是已知元素:

  1. 如果“app-actions-button”是一个 Angular 组件,则验证它是否是该模块的一部分。
  2. 如果“app-actions-button”是 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以禁止显示此消息。

检查我的模块:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { ActionsButtonRoutingModule } from '../actions-button/actions-button-routing.module';
import { ActionsButtonComponent } from './actions-button.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ModalModule } from "ngx-bootstrap/modal";

@NgModule({
  declarations: [ActionsButtonComponent],
  imports: [
    CommonModule,
    ActionsButtonRoutingModule,
    FormsModule, ReactiveFormsModule,
    ActionsButtonComponent
  ],
  exports: [ActionsButtonComponent],
})
export class ActionsButtonModule { }

【问题讨论】:

    标签: javascript angular typescript


    【解决方案1】:

    您的组件app-actions-button 没有@Output 属性并且无法编译。

    您可以在@Output Angular docs 中阅读有关如何实现它的更多信息

    【讨论】:

    • 有。我从'@angular/core'导入所有import {Component,OnInit,Output,EventEmitter};并注册了输出事件发射器
    • 组件内部应该有一个字段:@Output show = new EventEmitter()
    • 是的,我有。 @Output() 发送 = 新的 EventEmitter;和函数 send.emit('blabla')
    • 你在声明test.component的地方导入ActionsButtonModule吗?
    • 没有?为什么 ? ..为什么它很重要?
    猜你喜欢
    • 2017-10-11
    • 2021-04-20
    • 2018-07-08
    • 2021-11-11
    • 2021-01-23
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多