Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 组件选择器不是已知元素_Angular_Angular7 - Fatal编程技术网

Angular 组件选择器不是已知元素

Angular 组件选择器不是已知元素,angular,angular7,Angular,Angular7,我有两个模块AppModule和MyArtModule,其中声明了一些组件 当我尝试在GraphicsComponent中使用ConfirmComponent选择器时,它工作正常,但当我尝试在MyArtComponent中使用ConfirmComponent选择器时,它抛出了一个错误“artifi-confirm-alert”不是已知元素: “人工确认警报”不是已知元素: 如果'artifi confirm alert'是一个角度组件,则验证它是否是该模块的一部分 如果'artifi confi

我有两个模块
AppModule
MyArtModule
,其中声明了一些组件

当我尝试在
GraphicsComponent
中使用
ConfirmComponent
选择器时,它工作正常,但当我尝试在
MyArtComponent
中使用
ConfirmComponent
选择器时,它抛出了一个错误
“artifi-confirm-alert”不是已知元素:

“人工确认警报”不是已知元素:

  • 如果'artifi confirm alert'是一个角度组件,则验证它是否是该模块的一部分

  • 如果'artifi confirm alert'是一个Web组件,则将'CUSTOM_ELEMENTS_SCHEMA'添加到此组件的'@NgModule.schemas'中 以抑制此消息

    • 应用模块
      • 图形组件
      • 确认组件
      • MyArt模块
        • MyArtComponent

    应用模块代码

    @NgModule({
      declarations: [
        GraphicsComponent,
        ConfirmAlertComponent
      ],
      imports: [
        BrowserModule,
        MyArtModule
      ],
      ...
    })
    
    @NgModule({
      declarations: [
        MyArtComponent,
      ],
      imports: [
        CommonModule
      ],
      providers: [
        MyArtService
      ],
      exports: [
        MyArtComponent
      ]
    })
    

    MyArtModule代码

    @NgModule({
      declarations: [
        GraphicsComponent,
        ConfirmAlertComponent
      ],
      imports: [
        BrowserModule,
        MyArtModule
      ],
      ...
    })
    
    @NgModule({
      declarations: [
        MyArtComponent,
      ],
      imports: [
        CommonModule
      ],
      providers: [
        MyArtService
      ],
      exports: [
        MyArtComponent
      ]
    })
    

    复制的问题代码-

    我用
    OneComponent
    创建了
    OneModule
    ,用
    twomcomponent
    创建了
    TwoModule

    可以在AppComponent中访问


    但无法访问AppOne组件中的

    您的ConfirmComponent和GraphicsComponent位于同一模块中!所以他们认识对方! 但是您试图将ConfirmComponent用于另一个模块中的另一个组件(在您的示例中为MyArtModule),而该模块不知道该组件是否存在

    您必须导出ConfirmComponent,使其能够在整个应用程序中使用

    在AppModule的导出数组中添加ConfirmComponent

    exports: [
      ConfirmComponent
    ]
    

    您正在尝试访问子模块组件中的父模块组件。创建共享模块并在其中添加组件

    @NgModule({
      declarations: [ConfirmComponent],
      exports: [ConfirmComponent],
    })
    
    export class SharedModule {
    }
    
    并将其添加到AppModule中:

    @NgModule({
      declarations: [
        GraphicsComponent,
      ],
      imports: [
        BrowserModule,
        MyArtModule,
        SharedModule
      ],
      ...
    })
    
    并将其导入您的艺术模块:

    @NgModule({
      imports: [
        CommonModule,
        SharedModule
      ],
      declarations: [ConfirmAlertComponent],
      exports: [
        ConfirmAlertComponent
      ]
    })
    export class MyArtModule { }
    

    在AppModule的导出数组中添加了ConfirmComponent,但仍然存在相同的错误。能否发送confirm-component.ts文件中的内容?没有,只是一个新组件。请检查问题我添加了一个复制问题的链接。我为确认组件创建了一个新模块,并导入了应用程序模块,但仍然收到相同的错误,尝试在stackbliz中复制链接有问题。