angulardecoratorangular2-directivesangular2-decorators

Angular 2 - Get all @input() in directives or component


Is there a way to get all component or directive property with @Input decorators in angular 2?


Solution

  • If you want to get all inputs value you can go with ngOnChanges hook.

    class MyComponent implements OnChanges {
      @Input() myProp: any;
      ngOnChanges(changes: SimpleChanges) {
        console.log('ngOnChanges - myProp = ' + changes['myProp'].currentValue);
      }
    }