Luckyy
Luckyy

Reputation: 1031

Angular 9 - is not a known element

It was working till angular 7 now after updating it it throws error of unknown elements. It's happening for shared modules.

Reproducible Code: - https://stackblitz.com/edit/angular-ivy-pb3eea

So I have a parent component 'Parent', child component to be used inside router of 'Parent' - 'Child' a shared component to be used inside parent and child both - 'Shared'

So I have imported in both modules of parent and child. (As using lazy modules), in parent it works but not in child.

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TestChildRoutingModule} from './test-child.routing.module';
import { SharedModule } from '../shared/shared.module';

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

Upvotes: 4

Views: 2964

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222532

You are missing the declaration of TestChildComponent in the TestChildModule

@NgModule({
    declarations: [
      TestChildComponent
    ],
    imports: [
        CommonModule,
        SharedModule,
        TestChildRoutingModule
    ],
    exports: [
      TestChildComponent
    ]
})
export class TestChildModule { }

Here is the fixed STACKBLITZ

Upvotes: 5

Related Questions