I just upgraded from Angular 2 rc4 to rc6 and having troubles doing so.
I see the following error on my console:
Unhandled Promise rejection: Template parse errors:
'cl-header' is not a known element:
1. If 'cl-header' is an Angular component, then verify that it is part of this module.
2. If 'cl-header' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("<main>
[ERROR ->]<cl-header>Loading Header...</cl-header>
<div class="container-fluid">
<cl-feedbackcontai"): AppComponent@1:4
Here is my Header Component:
import { Component } from '@angular/core';
import { Router } from '@angular/router';
// own service
import { AuthenticationService } from '../../../services/authentication/authentication.service.ts';
import '../../../../../public/css/styles.css';
@Component({
selector: 'cl-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.css']
})
export class HeaderComponent { // more code here... }
Here is my Header Module:
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule } from '@angular/router';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HeaderComponent } from './../../../components/util_components/header/header.component.ts';
@NgModule({
declarations: [ HeaderComponent ],
bootstrap: [ HeaderComponent ],
imports: [ RouterModule, CommonModule, FormsModule ],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})
export class HeaderModule { }
I created a wrapper module called util module which imports the HeaderModule:
import { NgModule } from '@angular/core';
import {HeaderModule} from "./header/header.module";
// ...
@NgModule({
declarations: [ ],
bootstrap: [ ],
imports: [ HeaderModule]
})
export class UtilModule { }
Which is finally imported by the AppModule:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import {UtilModule} from "./modules/util_modules/util.module";
import {RoutingModule} from "./modules/routing_modules/routing.module";
@NgModule({
bootstrap: [AppComponent],
declarations: [AppComponent],
imports: [BrowserModule, UtilModule, RoutingModule]
})
export class AppModule { }
To my understanding I am following the instructions of the error message using the SCHEMA to surpress the error. But it seems not to work. What am I doing wrong? (I hope its nothing obvious I just don't see at the moment. Been spending the past 6 hours upgrading to this version...)
For me, I needed to look at :
1. If 'cl-header' is an Angular component, then verify that it is part of this module.
This means that your component isn't included in the
app.module.ts
. Make sure it's imported and then included in thedeclarations
section.I think you are using a custom module. You can try the following. You need to add the following to the file your-module.module.ts:
Just wanted to add a little bit more on this.
With the new angular 2.0.0 final release (sept 14, 2016), if you use custom html tags then it will report that
Template parse errors
. A custom tag is a tag you use in your HTML that's not one of these tags.It looks like the line
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
need to be added to each component where you are using custom HTML tags.EDIT: The
schemas
declaration needs to be in a@NgModule
decorator. The example below shows a custom module with a custom componentCustomComponent
which allows any html tag in the html template for that one component.custom.module.ts
custom.component.ts
custom.component.html
In here you can use any HTML tag you want.
util.component.ts
util.module.ts
LogoutComponent Needs to be exported
dashboard.module.ts
import
AccountModule
in module where we want to use<app-logout>
import { AccountModule } from 'util.module';dashboard.component.ts
I am not required to import and use
CUSTOM_ELEMENTS_SCHEMA
.however its not working when dashboard.module is lazy loaded.
When using
CUSTOM_ELEMENTS_SCHEMA
in case of lazy loading, error is suppressed but the component is not added to dom.Hey this is fixed by doing
a) adding
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
to every component orb) adding
and
to your module.
Cheers, Raphael
Just read this post and according to the angular 2 docs:
So just in case anyone runs into this problem, once you have added CUSTOM_ELEMENTS_SCHEMA to your NgModule, make sure that whatever new custom element you use has a 'dash' in its name eg. or etc.