There are various type of component selectors. You can choose based on your liking. Here are the examples:
1. Tag Selector (Default):
@Component({
selector: 'app-component',
})
Above will render as (created automatically or dynamically, it will look same):
<app-component></app-component>
2. Class Selector:
@Component({
selector: '.app-component',
})
Above will render as (automatically created by router or any other possible means):
<div class=”app-component”></div>
Note: Since this is class type selector, you can apply it to any tag when you are using it manually. Like below i can apply the same selector to a html <section>
tag:
<section class=”app-component”></section>
Above logic will be true for rest of other type of selectors.
3. ID Selector:
@Component({
selector: '#app-component',
})
Above will render as (automatically created by router or any other possible means):
<div id=”app-component”></div>
Note: Since ID should only exist uniquely once over the whole page rendering, this type of selectors shouldn't be used for components which repeated via any iterators or can be placed multiple times on a given page render.
4. Attribute Selector:
@Component({
selector: '[app-component]',
})
Above will render as (automatically created by router or any other possible means):
<div app-component></div>
Note: This is the best choice and should have been the default selector for the angular by all means.
With all the above, in your component style you can place the below style to make the parent container get out of the way from the css styling of the parent of the component and children of the component:
:host {
display: contents;
}
If you guys think that I have missed out anything, please help me complete the above answer.
Note: There are some other ways which intentionally left here untouched here as there are performance hit on rendering engine by using them. See few options by others here on this stackoverflow question.