Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 Component selector: array like '[ui-components]'

Tags:

angular

I've realized sometimes I've seen angular2 code as:

@Component({
  selector: '[ui-components]'

What does selector: '[ui-components] mean?

like image 476
Jordi Avatar asked Dec 14 '16 09:12

Jordi


People also ask

What is a component selector?

A selector is one of the properties of the object that we use along with the component configuration. A selector is used to identify each component uniquely into the component tree, and it also defines how the current component is represented in the HTML DOM.

Can a component have multiple selectors?

With , separated multiple selectors can be used where the component is added to elements where one of these matches. Many of Angulars built-in directives use a list of selectors.


1 Answers

It means you are making the component as an attribute component instead of an element component. When you use the component in your html, you write

<div ui-components></div>

if you use

@Component({
  selector: 'ui-components' // without the brackets

you have to use this notation in your html

<ui-components></ui-components>

Here are some readings from the Angular2 documentation.

like image 106
John Avatar answered Sep 23 '22 09:09

John