Reputation: 67
I have a problem with my angular2 app. I have that code:
// app.component.ts
import {Component} from '@angular/core';
import {CoursesComponent} from './courses.component'
@Component({
selector: 'my-app',
template: `<h1>Hello</h1><my-courses></my-courses>`,
directives: [CoursesComponent]
})
export class AppComponent {
name = 'Angular2';
}
and
// courses.component.ts
import {Component} from '@angular/core';
@Component({
selector: 'my-courses',
template: '<h2>Courses</h2>'
})
export class CoursesComponent {
}
And my app doesn't work. After I deleted <my-courses></my-courses>
from template in app.component.ts it started working, but without my courses component.
After i add this back, it will cause that errors:
What I do wrong with that?
Upvotes: 0
Views: 50
Reputation: 24874
Are the components part of the same module
?
If so, I guess that you aren't importing / declaring the component
in your module
.
Do this:
import { CoursesComponent } from './your-path';
// ... other imports
@NgModule({
bootstrap: [ AppComponent ],
declarations: [
AppComponent,
CoursesComponent
...
],
// ...
export class AppModule { ... }
Also, you don't need to import CoursesComponent
in AppComponent
, just in AppModule
.
Upvotes: 1
Reputation: 4013
Just add this to your ngModule:
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
import CUSTOM_ELEMENTS_SCHEMA
from @angular/core
This is because you have a -
in your component selector.
Upvotes: 0