相关疑难解决方法(0)

从Angular 2组件中访问`selector`

我试图找出如何访问selector我们传递给 @Component装饰器的内容.

例如

@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
  }
}
Run Code Online (Sandbox Code Playgroud)

最后,我想使用它来创建一个自动添加属性的指令,data-tag-name="{this.component.selector}"以便我可以使用Selenium查询通过其选择器可靠地找到我的角度元素.

我没有使用量角器

angular2-directives angular2-components angular2-decorators angular

12
推荐指数
4
解决办法
8532
查看次数