Can't add a new component to my angular 2 app with typescript Can't add a new component to my angular 2 app with typescript typescript typescript

Can't add a new component to my angular 2 app with typescript


Angular2 Component decorator no longer use these for embedding other components. We will need to use a new meta data called entryComponents instead. See below as an example ...

@Component({  selector: 'app-root',  templateUrl: './app.component.html',  styleUrls: ['./app.component.css'],  entryComponents:[VehicleListComponent]})

The vehicle-list-component has the following component metadata..

@Component({  selector: 'app-vehicle-list',  templateUrl: './vehicle-list.component.html',  styleUrls: ['./vehicle-list.component.css'],  providers: [VehicleService]})


Error itself says that directives doesn't exist in Component as it has been deprecated. try this code shown below,

import { MyComponentComponent } from './my-component/my-component.component'import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';@NgModule({   ...   ...   declarations:[AppComponent,MyComponentComponent], //<---need to declare    schemas:     [CUSTOM_ELEMENTS_SCHEMA]             //<---added this line})

And remove directives:[MyComponentComponent] from AppComponent.


if you use Angular CLI then the new component will be automatically imported and added to declarations section of @ngmodule in app.module.ts . We don't need to write any code for that.