-2

Below is sample angular project which implements a sample Users Listing with datagrid row expand feature. Now as a standalone webapp, it is throwing error while navigating to next page as shown below: enter image description here

If I comment the "" in parent component. the error will disappear.

Steps to run project:

prerequisite: 1. node.js version 6.9 or higher 2. npm install 3. npm install -g json-server

Run:

  1. start json-server to get mock data and load local message bundles(cmd terminal #1) npm run json-server
  2. run the plugin in dev mode and watches your files for live-reload (cmd terminal #2) ng serve
  3. Problematic Code Files path "testplugin-ui\src\app\users*"

Here is the project seed with code https://drive.google.com/open?id=1Meeo_SXZEJfYyboihimJGr2DtJHeMP8k or https://nofile.io/f/q4FerHzV0Z0

As I need json-server, I'm uploading sample project instead of plunker/stackblitz. let me know what is wrong with this code.

Vikas
  • 11,859
  • 7
  • 45
  • 69
shravan
  • 85
  • 9

2 Answers2

3

From Datagrid expandable rows additional features, it would seem you have the *clrIfExpanded directive in the wrong place.

user-row-detail.component.ts

<ng-template ngFor let-child [ngForOf]="children" *clrIfExpanded>
    <clr-dg-row-detail>
        <clr-dg-cell>{{child.username}}</clr-dg-cell>
        <clr-dg-cell>{{child.fullName}}</clr-dg-cell>
        <clr-dg-cell>{{child.role}}</clr-dg-cell>
    </clr-dg-row-detail>
</ng-template>

instead of

<ng-template ngFor let-child [ngForOf]="children">
    <clr-dg-row-detail *clrIfExpanded>
        <clr-dg-cell>{{child.username}}</clr-dg-cell>
        <clr-dg-cell>{{child.fullName}}</clr-dg-cell>
        <clr-dg-cell>{{child.role}}</clr-dg-cell>
    </clr-dg-row-detail>
</ng-template>
Richard Matsen
  • 20,671
  • 3
  • 43
  • 77
1

@shravan,

There are quite a lot of problems with the code, including at least 35 Circular dependency warnings… Anyway, you might want to refactor your code, but for the time being, try changing your UserRowDetailComponent to this:

@Component({
  selector: 'user-row-detail',
  templateUrl: './user-row-detail.component.html',
  encapsulation: ViewEncapsulation.Emulated
})
export class UserRowDetailComponent implements OnInit, OnDestroy {
  @Input() children: Array<User>;

  constructor(private cd: ChangeDetectorRef) {
      console.log("calling UserRowDetailComponent Comp constructor!");
  }

  ngOnInit() {
    this.cd.detectChanges(); //Force change detection here
    console.log("calling detectChanges user-row-detail from OnInit!");
  }

  ngOnDestroy() {
      console.log("calling UserRowDetailComponent onDestroy!");
  }
}

As you can see, I have added a forced change detection. You might want to review the blog post suggested by @Vikas to understand what is going on here.

Jose Gomes
  • 36
  • 3