【问题标题】:Angular 2 - Get all @input() in directives or componentAngular 2 - 获取指令或组件中的所有@input()
【发布时间】:2016-12-03 23:45:58
【问题描述】:

有没有办法使用 Angular 2 中的 @Input 装饰器获取所有组件或指令属性?

【问题讨论】:

  • 组件或指令属性是什么意思?
  • 使用 @Inputs() 装饰器声明的类的所有属性。

标签: angular decorator angular2-directives angular2-decorators


【解决方案1】:

如果您想获取所有输入值,您可以使用 ngOnChanges 钩子。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 2023-04-06
    • 2017-10-19
    • 1970-01-01
    • 2018-08-31
    • 2016-11-13
    • 2020-03-31
    相关资源
    最近更新 更多