【问题标题】:Angular 10 use a component inside an other (error : is not a known element)Angular 10 在另一个内部使用一个组件(错误:不是已知元素)
【发布时间】:2021-04-12 13:07:18
【问题描述】:

我遇到了问题。我正在使用 Angular 11 启动一个应用程序。 我正在尝试创建一个抵抗页面:注册。

  • 我创建了一个“用户”模块,其中包含有关用户的每个模块(注册、登录、信息...)
  • 在用户模块中,我创建了一个模块注册,其中包含注册页面的每个模块(一些信息、表格...)
  • 在注册模块中,我创建了 2 个组件:SignupComponent(=一些信息)和 FormSignUpComponent(=表单注册)。

当我在应用程序午餐时收到此错误消息:

'i-form-sign-up' is not a known element:
1. If 'i-form-sign-up' is an Angular component, then verify that it is part of this module.
2. If 'i-form-sign-up' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

但是,FormSignUpComponent 是在 SignupModule 中声明的:/

你能帮帮我吗?

我有这个层次结构:

注册模块:

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

import { SignupComponent } from './signup.component';
import { UiModule } from '../../core/ui/ui.module';
import { FormSignUpComponent } from './form-sign-up/form-sign-up.component';

@NgModule({
  declarations: [
    SignupComponent,
    FormSignUpComponent
  ],
  imports: [
    CommonModule,
    UiModule
  ]
})
export class SignupModule { }

SignUp.component.html:

<div class="form-container">
    <i-form-sign-up></i-form-sign-up>
    <section>
        ... some informations
    </section>
</div>

FomSignUpComponent:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'i-form-sign-up',
  templateUrl: './form-sign-up.component.html',
  styleUrls: ['./form-sign-up.component.css']
})
export class FormSignUpComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
}

【问题讨论】:

  • 一个愚蠢的评论,但无论如何:终止ng serve并重新运行它(如果你没有这样做,重新编译)

标签: angular module components


【解决方案1】:

您可能还没有导入注册模块。这也是使用 Angular 的一种奇怪方式。你不应该在模块中有模块。

【讨论】:

    猜你喜欢
    • 2021-09-16
    • 2017-04-28
    • 1970-01-01
    • 2017-11-09
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多