【问题标题】:@query is not working on inherited classes@query 不适用于继承的类
【发布时间】:2016-06-28 13:41:57
【问题描述】:

假设我有: ConcreteClass 扩展 BaseClass{}

当尝试使用 @Query(BaseClass) 时, Angular什么也没找到。 只有当我查询 ConcreteClass 时,我才会得到结果; 有什么想法吗?

【问题讨论】:

标签: angular


【解决方案1】:

不支持在@ViewChild(SubClass) 中按子类查找。

https://github.com/angular/angular/issues/1828

解决方法在https://github.com/angular/angular/issues/8580#issuecomment-218525425中进行了说明

@Component({
  selector: 'my-fancy-item',
  providers: [{provide: MyItem, useExisting: MyFancyItem}]
})
class MyFancyItem extends MyItem {}

查询MyItem 会查找MyItemMyFancyItem。不过我没试过。

【讨论】:

  • 谁否决了这个?那里有什么问题?我赞成,因为这表明了正确的方向!
猜你喜欢
  • 2017-01-24
  • 1970-01-01
  • 2020-05-07
  • 2017-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-11
  • 1970-01-01
相关资源
最近更新 更多