0

I'm busy working with the angularSlickgrid library on an Angular project. I created a dropdown component to use inside my grid but here is the problem ... When I try to import the component and call it without a constructor it loads and the dropdrown creates fine.. but as soon as I try to load the same component via its constructor I get the following error :

"Error: Uncaught (in promise): Error: No component factory found for [object Object]. Did you add it to @NgModule.entryComponents?

I've already made sure my imports are correct here is the relevant parts of my autenticated.module.ts :

import { CrmGridViewComponent } from './crm/crmGridListView/crnm-grid-view/crnm-grid-view.component';
import { GridDropDownCreator } from './components/gridDropdownComponent/gridDropDown';

declarations: [
    CrmGridViewComponent,
    GridDropDownCreator,
],
  entryComponents: [
   GridDropDownCreator,
   CrmGridViewComponent, 
]

Now like I said if the dropdown component doesn't have a constructor it works... dropdown :

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-dropdown',
  template: `
   <div id="{{dropdownId}}" class="dropdown" style="position:absolute; z-index:12000;">
  <a class="dropdown-toggle"
     id="{{dropDownToggleId}}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Actions
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu padding10">
    <li><span class="text-primary text-center" >{{dataContext.title}}</span></li>
    <li role="separator" class="divider"></li>
    <li><span class='pointer'>View contacts</span></li>
    <li><span class='pointer'>Edit</span></li>
      <li><span class='pointer'>Delete</span></li>
  </ul>
</div>`,
  //templateUrl: './dropdown.component.html',


})
export class GridDropDownCreator {
  // constructor(labelFor: string) { //uncommented is wat I actually want to achieve.. this is a test for bigger data to come
  //   console.log('the constructor fired : ');
  // }
  parent: any; // parent component context
  row: number;
  dataContext: any;
  dropdownId = 'companyDropDown';
  dropDownToggleId = 'toggleDrop';
}

here is where I try to access the component :

import { Column, GridOption, AngularUtilService, Formatters, AngularGridInstance, BsDropDownService, OnEventArgs } from 'angular-slickgrid';
import { GridDropDownCreator } from 'pathToFile/gridDropdownComponent/gridDropDown';


  prepareGrid() {
    this.columnDefinitions = [
      // ['name', 'surname', 'telNr', 'cellNr', 'email', 'tags', 'options'];
      { id: 'name', name: 'Name', field: 'name', sortable: true, filterable: true, },
      { id: 'category', name: 'Category', field: 'category', sortable: true, filterable: true },
      { id: 'vatNo', name: 'vatNo', field: 'vatNo', sortable: true, filterable: true },
      { id: 'description', name: 'Description', field: 'description', sortable: true, filterable: true },
      { id: 'tags', name: 'Tags', field: 'tags', sortable: true, filterable: true },
      {
        id: 'action',
        name: 'Action',
        field: 'id',
        formatter: Formatters.bsDropdown,
        params: { label: 'Action' },
        onCellClick: (e: Event, args: OnEventArgs) => {
         // const comp = new GridDropDownCreator('company'); //this is what I want but it doesn't work this way
          this.bsDropdown.render({
            component: comp, //change this to the imported dropdown (GridDropDownCreator) and comment out the constructor and it will display the dropdown
            args,
            offsetLeft: 92,
            offsetDropupBottom: 15,
            parent: this, // provide this object to the child component so we can call a method from here if we wish
          });
        },
        // exportCustomFormatter: Formatters.complexObject,
        // asyncPostRender: this.renderAngularComponent.bind(comp),
      }
    ];

    this.gridOptions = {
      enableAutoResize: true,
      enableSorting: true,
      enableColumnReorder: false, 
      enableFiltering: true,
      enablePagination: true,
      enableAsyncPostRender: true, 
      asyncPostRenderDelay: 0,    
      rowHeight: 50,
      rowSelectionOptions: {
        // True (Single Selection), False (Multiple Selections)
        selectActiveRow: false
      },
      params: {
        angularUtilService: this.angularUtilService // provide the service to all at once (Editor, Filter, AsyncPostRender)
      }
    };

    // fill the dataset with your data
    this.dataset = [ /** ...your data... **/];
  }

To Sumarize the question how Do I call the GridDropDownCreator via is constructor ? without it giving me this error : "Error: Uncaught (in promise): Error: No component factory found for [object Object]. Did you add it to @NgModule.entryComponents?

thanks guys!

Andre
  • 41
  • 5
  • I think you made a typo in the `render` properties, instead of this `component: comp,` it should be `component: GridDropDownCreator,`. The Component is instantiated in the `BsDropDownService` on this [line](https://github.com/ghiscoding/Angular-Slickgrid/blob/master/src/app/modules/angular-slickgrid/services/bsDropdown.service.ts#L73). This feature was done by another user and couple months after I added a new [Cell Menu & Context Menu](https://ghiscoding.github.io/Angular-Slickgrid/#/context), the Cell Menu does the same thing but without an external Angular Component which I prefer – ghiscoding Jun 11 '20 at 12:45
  • thanks for the reply man. the only reason I use the ```component:comp``` is cause I'll need to pass data to another component (going to try hit a nested angular-slickgrid layout). also is there anyway to see the example code for the cell menue & context menu ? I've been on the demo page a few times and can't seem to find the code hahah – Andre Jun 11 '20 at 13:31
  • I'd also like to stick to the lib as much as possible haha – Andre Jun 11 '20 at 13:33
  • 1
    the easiest is to clone the [angular-slickgrid-demos](https://github.com/ghiscoding/angular-slickgrid-demos) repo. I didn't write a Wiki for it, there's just so much hours in a day and never got to it, plus I'm not sure how many people are using the Wikis... it's mainly just me working on the lib, I wish to have more contributions sometimes, even writing Wikis could help – ghiscoding Jun 11 '20 at 13:46
  • 1
    So just to be clear, the `cellMenu` is commonly used as an Action Menu from the demos that I told you to clone on previous comment, you can see how it is configured on this [line](https://github.com/ghiscoding/angular-slickgrid-demos/blob/master/bootstrap3-demo-with-translate/src/app/examples/grid-contextmenu.component.ts#L170). I forgot that I had already created a [Wiki - Cell Menu](https://github.com/ghiscoding/Angular-Slickgrid/wiki/Cell-Menu) and [Wiki - Context Menu](https://github.com/ghiscoding/Angular-Slickgrid/wiki/Context-Menu).. You can also upvote if you like the lib ;) – ghiscoding Jun 11 '20 at 20:16

0 Answers0