One of the most used frameworks in recent years to build the frontend part of an application or website is Angular. This is how they define it on their official website “Angular is a development platform, built on TypeScript”.
Angular gives a business the ability to have a scalable website with a new design. For a software company, using this framework has several benefits and uses, among which are: creating forums, business portals, crowdfunding platforms, marketplaces, property listings, etc.
Among the companies that have made use of this framework for their pages and applications are: GitHub (forum), Google, Forbes, Indiegogo, BMW (price calculator, offer search engine), Deutsche Bank developer portal, Crunchbase, Nike , Xbox, Udacity , YoutubeTV, Firebase, AT&T and Adobe.
Angular offers its users several components that make development an easy and fast task, among these, it stands out in view encapsulation or encapsulated view according to its translation into Spanish, which they explain on the framework page.
There they tell us “In Angular, the styles of a component can be encapsulated within the host element of the component so that they do not affect the rest of the application. The component decorator provides the encapsulation option that can be used to control how the per-component encapsulation is applied.
The developer can choose from the following modes:
The following example shows an element that contains ViewEncapsulation.None
@Component({ selector: 'app-no-encapsulation', template: ` <h2>None</h2> <div class="none-message">No encapsulation</div> `, styles: ['h2, .none-message { color: red; }'], encapsulation: ViewEncapsulation.None, }) export class NoEncapsulationComponent { }
The following example shows an element that contains the ViewEncapsulation.Emulated component.
@Component({ selector: 'app-emulated-encapsulation', template: ` <h2>Emulated</h2> <div class="emulated-message">Emulated encapsulation</div> <app-no-encapsulation></app-no-encapsulation> `, styles: ['h2, .emulated-message { color: green; }'], encapsulation: ViewEncapsulation.Emulated, }) export class EmulatedEncapsulationComponent { }
Similar to ViewEncapsulation.None, Angular adds the styles for this component to the <head> of the document, but with "scoped" styles.
Therefore, only elements directly within this component's template will match its styles. Since the "scoped" styles of the EmulatedEncapsulationComponent are very specific, they override the global styles of the NoEncapsulationComponent.
Now, let's look at an example component that contains ViewEncapsulation.ShadowDom
@Component({ selector: 'app-shadow-dom-encapsulation', template: ` <h2>ShadowDom</h2> <div class="shadow-message">Shadow DOM encapsulation</div> <app-emulated-encapsulation></app-emulated-encapsulation> <app-no-encapsulation></app-no-encapsulation> `, styles: ['h2, .shadow-message { color: blue; }'], encapsulation: ViewEncapsulation.ShadowDom, }) export class ShadowDomEncapsulationComponent { }
On the Angular page they explain "in this example, the ShadowDomEncapsulationComponent contains both the NoEncapsulationComponent and the EmulatedEncapsulationComponent".
Our Rootstack developers have used Angular to design dynamic applications focused on a good user experience when interacting with them, thus being able to solve the technical problems of our international clients.