D
D
Drovosek012021-05-27 11:19:10
Angular
Drovosek01, 2021-05-27 11:19:10

How to find out the name of the selector of this component in the code of the Angular component?

For example, there is such a component.

@Component({
  selector: 'app-test',
  templateUrl: './app-test.component.html',
  styleUrls: ['./app-test.component.scss']
})
export class Test {

}


As in the code, in the Test class, find out the value of the selector field, i.e. get the string 'app-test' in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sun_Day, 2021-05-27
@Drovosek01

@Component({
  selector: 'app-test',
  templateUrl: './app-test.component.html',
  styleUrls: ['./app-test.component.scss']
})

export class Test {
  constructor(element: ElementRef<HTMLElement>) {
    const tagName = element.nativeElement.tagName.toLowerCase();
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question