我在想如何访问我们传入@Component
装饰器的selector
。从Angular 2组件中访问`selector`
例如
@Component({
selector: 'my-component'
})
class MyComponent {
constructor() {
// I was hoping for something like the following but it doesn't exist
this.component.selector // my-component
}
}
最后,我想用它来创建一个指令,它会自动添加一个属性data-tag-name="{this.component.selector}"
,这样我可以用Selenium查询可靠地找到我通过自己选择的角度元素。
我不是用量角器
这可能是现在唯一的方法,现在更老的(现在打破)的方式更好,因为它不需要添加注入,并且可以在不需要实例的情况下访问它,在写入结束时使用它结束测试以减少重复。 –