jaumard / ngx-dashboard

Dashboard library for angular 4 and more
https://jaumard.github.io/ngx-dashboard/demo/demoDist/index.html
MIT License
71 stars 31 forks source link

ngOnInit() called twice in Widget component #33

Open anvial opened 7 years ago

anvial commented 7 years ago

Hello,

I use standard widget component template. See next:

@Component({
  selector: 'line-widget',
  templateUrl: './line-widget.component.html',
  styleUrls: ['./line-widget.component.css'],
  providers: [{provide: WidgetComponent, useExisting: forwardReference}]

})
export class LineWidgetComponent extends WidgetComponent implements OnInit {
  @ViewChild(WidgetHandleDirective) protected _handle: WidgetHandleDirective;

  @Input() public size: number[] = [2, 2];
  @Input() public widgetId: string;
  @Output() onClose = new EventEmitter<any>();

  // somecode

  constructor(
    ngEl: ElementRef,
    renderer: Renderer2
  ) {
    super(ngEl, renderer);
  }

  ngOnInit() {
    super.ngOnInit();
    console.warn('line chart');
  }

  closeWidget() {
    this.onClose.emit(this.widgetId);
  }

}

The problem is when I'm adding this widget to dashboard – the ngOnInit() method called twice.

Any suggestions? Thank You.

jaumard commented 6 years ago

Hi,

Do you have the same problem with the demo app ?? Would be nice to be able to reproduce it on it. Will be easier to understand what's going on