JulianMayer
JulianMayer

Reputation: 25

Angular - template parse errors <component> is not a known element

I'm trying to import a component into another component but the imported component doesn't seem to be found. Here is the error message:

Uncaught Error: Template parse errors:
'aktenkorrespondenzenTemplate' is not a known element:
1. If 'aktenkorrespondenzenTemplate' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
                            <div class="viewaktenkorrespondenz">
                                [ERROR ->]<aktenkorrespondenzenTemplate #aktenkorrespondenzenTemplate></aktenkorrespondenzenTemplate>
        "): ng:///AppModule/CreateOrEditAkteComponent.html@54:32 

main.module.ts

[...]
import { AktenkorrespondenzenTemplateComponent } from '@app/main/shared/aktenkorrespondenzen/aktenkorrespondenzen-template.component';
@NgModule({
    imports: [
        [...]
    ],
    declarations: [
        [...]
        AktenkorrespondenzenTemplateComponent
    ]
})
export class MainModule { }

aktenkorrespondenzen-template.component.ts

@Component({
    selector: 'aktenkorrespondenzenTemplate',
    templateUrl: './aktenkorrespondenzen-template.component.html',
    styleUrls: ['./aktenkorrespondenzen-template.component.less'],
    animations: [appModuleAnimation()],
})

export class AktenkorrespondenzenTemplateComponent extends AppComponentBase implements OnInit {
[...]
}

create-or-edit-akte.component.ts

import { AktenkorrespondenzenTemplateComponent } from '@app/main/shared/aktenkorrespondenzen/aktenkorrespondenzen-template.component';

export class CreateOrEditAkteComponent extends AppComponentBase implements OnInit {
    @ViewChild('aktenkorrespondenzenTemplate') aktenkorrespondenzenTemplate: AktenkorrespondenzenTemplateComponent;
}

create-or-edit-akte.component.html

<div class="viewaktenkorrespondenz">
    <aktenkorrespondenzenTemplate #aktenkorrespondenzenTemplate></aktenkorrespondenzenTemplate>
</div>

I would be very thankful for possible solutions.

Upvotes: 1

Views: 1334

Answers (1)

Amir Christian
Amir Christian

Reputation: 595

Please confirm if MainModule is imported in AppModule and then try this

Create AktenkorrespondenzenModule and import it in MainModule or import it in AppModule directly.

Or try this:

[...]
import { AktenkorrespondenzenTemplateComponent } from '@app/main/shared/aktenkorrespondenzen/aktenkorrespondenzen-template.component';
@NgModule({
    imports: [
        [...]
    ],
    declarations: [
        [...]
        AktenkorrespondenzenTemplateComponent
    ],
    exports: [
        [...]
        AktenkorrespondenzenTemplateComponent
    ]
})
export class MainModule { }

Upvotes: 1

Related Questions