'tables-basic' is an Angular component, th

2019-09-03 16:54发布

问题:

I have a table-basic.component.ts in which i declared 'tables-basic' as a selector and i am calling the template in dashboard.html and i followed the below process but still i did got an error,which i also mentioned below.

My dashboard.template.html,

  <div href='#tab2'>
      <div id='tab2'>
       <tables-basic></tables-basic>
       </div>
     </div>

My ts,

import { Component, ViewEncapsulation } from '@angular/core';
import { TablesBasic } from '../tables/basic/tables-basic.component';
import { AppConfig } from '../app.config';

@Component({
  selector: 'dashboard',
  templateUrl: './dashboard.template.html'

})
export class Dashboard {
  config: any;
  month: any;
  year: any;
}

Error,

   main.browser.ts:25Error: Template parse errors:(…)(anonymous function) @ main.browser.ts:25ZoneDelegate.invoke 
      @ zone.js:203Zone.run 
      @ zone.js:96(anonymous function) 
      @ zone.js:462ZoneDelegate.invokeTask 
      @ zone.js:236Zone.runTask 
      @ zone.js:136drainMicroTaskQueue 
      @ zone.js:368ZoneTask.invoke 
      @ zone.js:308

I dont know about this error,can any one suggest help please.

回答1:

You need to add TableBasicComponent to declarations of parent components module.

import { TableBasicComponent } from 'path/to/component'

@NgModule({
  declarations: [
    TableBasicComponent // < --- added here
  ],
  imports: [
  ],
  providers: []
})
export class DashboardModule { }