I am noob with Angular 2. I am doing YouTube tutorials, but every tutorial have the directives:
part where i am stuck.
app.component.ts
import { Component } from '@angular/core';
import { HeaderComponent } from './components/header/header.component'
@Component({
selector: 'my-app',
template: '<h1>Hello</h1><header></header>',
directives: [HeaderComponent]
})
export class AppComponent { }
Argument of type '{ selector: string; template: string; directives: typeof HeaderComponent[]; }' is not assignable to parameter of type 'ComponentMetadataType'.at line 6 col 3
header.component.ts
import { Component } from '@angular/core';
@Component ({
selector: 'header',
template: '<h2>hit!</h2>'
})
export class HeaderComponent { }
directives
property was removed in RC.6
You should move it to declarations
property of your NgModule decorator
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent, HeaderComponent ], <== here
bootstrap: [ AppComponent ]
})
export class AppModule { }
If you are using RC6, then only you should do following,
import { HeaderComponent } from './components/header/header.component' //<----added this line
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent,HeaderComponent], //<----added HeaderComponent
bootstrap: [ AppComponent ]
})
This is a very common problem faced if you are new to angular2
and this answer is probably for those who are stuck with the similar kind of problem.
First of all, don't forget to import the child component class(here, HeadComponent) in your root component(app.component.ts
) as follows:-
//inside app.component.ts
import{ HeadComponent} from'./components/header/header.component';
Then you should move it to declarations in app.module.ts
follows:-
import{ TutorialsComponent} from'./components/header/header.component';
@NgModule({
declarations: [
AppComponent,HeadComponent]
I guess this should help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With