访问角度组件元数据

时间:2017-12-05 11:47:36

标签: javascript angular reflection jasmine

是否可以获得例如changeDetection属性被定义为给定组件的装饰的一部分?

import { Component, ChangeDetectionStrategy } from '@angular/core';

@Component({
  selector: 'app-banner',
  template: '<h1>{{title}}</h1>',
  changeDetection: ChangeDetectionStrategy.OnPush
})

export class BannerComponent { }

我试过了:

Reflect.getMetadataKeys(BannerComponent) // []
Reflect.getOwnMetadataKeys(BannerComponent) // []
Reflect.getMetadata('annotations', BannerComponent) // undefined

https://plnkr.co/edit/VXfcZH9BWPWbdyBOJRTV?p=preview

1 个答案:

答案 0 :(得分:0)

看似 hacky 但是无法解决问题:

BannerComponent['__annotations__'][0]

https://plnkr.co/edit/HAbomBljAACHVz6N33m5?p=preview

积分this SO answer