Ng2-smart-table custom Render component

6.3k Views Asked by At

Im trying to use a custom Renderer component in my ng2-smart-table but am getting the following error.

No component factory found for undefined. Did you add it to @NgModule.entryComponents?
    at…, …}

Whats Strange is that the component says its undefined.

My component looks like this.

import { Component, OnInit, Input } from '@angular/core';
import { ChannelTableModeService } from '../../../../../../services/channel-table-mode.service';
import { ViewCell } from 'ng2-smart-table';

@Component({
  selector: 'app-channel-attribute-renderer',
  template: '{{renderValue}} --'
})
export class ChannelAttributeRendererComponent implements OnInit {

constructor() { }
  renderValue: string;
  @Input() value: string | number;
  @Input() rowData: any;
  ngOnInit() {
     this.renderValue =  '<' + this.value + '>';
  }

}

I've also made sure that the component is in the module.

    @NgModule({
      imports: [
        Ng2SmartTableModule,
        CommonModule,
        ChannelProfileRoutingModule,    
        VeexCommonModule,
        TranslateModule,
        FormsModule
      ],
      entryComponents: [ChannelAttributeRendererComponent, PasswordRenderComponent],
      providers: [ChannelTableModeService],
      declarations: [ PasswordRenderComponent, ChannelProfileComponent, ChannelTableComponent, ServiceTypeComponent, ServiceGroupComponent, ChannelPlanEditorComponent, ChannelAttributeRendererComponent]
    })

export class ChannelProfileModule { }

So does anyone see the issue. Why does he factory think that the component is undefined.

The configuration form my smart table looks like this:

this.settings = { 
columns: {
  'Channel': {title: 'Channel'},
  'Channel Label': {title: 'Channel Name'},
  'Video': {title: 'Video', type: 'custom', renderComponent: 
PasswordRenderComponent}
}}
2

There are 2 best solutions below

0
On BEST ANSWER

Try getting the distribution code of ng2-smart-table from github and replace your existing ng-smart-table code in node_modules directory.

I had too had a similar issue, I fixed it by replacing the ng-smart-table module from distribution

0
On

Had the same "No component factory found for undefined. Did you add it to @NgModule.entryComponents?" I fixed it by changing "renderComponent" to "component" in the column definition.

I found this by looking at the error in dev tools, it tries to get the render component from ".component" which is undefined if you use renderComponent