Skip to content

Latest commit

 

History

History
31 lines (25 loc) · 664 Bytes

Reload child component when variables on parent component changes.md

File metadata and controls

31 lines (25 loc) · 664 Bytes

References

Summary

  • Child component:
import { Component, OnChanges, Input } from '@angular/core';

@Component({
  selector: 'child',
  templateUrl: 'child.component.html',
})

export class ChildComponent implements OnChanges {
  @Input() paramFromParentComponent;

  ngOnChanges(changes) {
    if (!changes.paramFromParentComponent.firstChange
      && changes.paramFromParentComponent.previousValue != changes.paramFromParentComponent.currentValue)
    {
      // your code to reload
    }
  }
}
  • Parent component:
<child [paramFromParentComponent]="paramFromParentComponent"></child>