I've realized sometimes I've seen angular2 code as:
@Component({
selector: '[ui-components]'
What does selector: '[ui-components]
mean?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With