Published on 01/15/2018 12:57 pm
View Encapsulation in Angular 4 - Types & Examples in JavaScript
View Encapsulation is a way that defines whether components styles will affect the whole application or not i.e it has control over usage of component styles, use styles globally or should be limited to a particular Angular component (scoped styles).

Angular Components can be styled via inline styles through styles property or via external styles through styleUrls which are the property of @Component decorator.
Example
In default root component “app.component.ts” adding style
- Inline styles through styles property.
@Component({selector: 'app-root',templateUrl: './app.component.html',styles: [`h1 {color: #369;font-family: Arial, Helvetica, sans-serif;font-size: 250%;}`]})export class AppComponent {title = 'Angular 4 app';}
- External styles through styleUrls property.
import { Component } from '@angular/core';@Component({selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css']})export class AppComponent {title = 'Angular 4 app';}
Above mentioned component styles are appended to document head. But by using native Shadow DOM the component styles will be included in component’s template.
Read more: ViewEncapsulation in Angular 4 – Types & Examples in JavaScript Application
0 Comments

Guest
Please login to post your comment..

Web Development Blogs
Categories
Tags
informaticamdmdatabasedata integrationandroidandroid appsandroid tutorialandroid componentmobile developmentmobile app developmentdevelopmenttechnologyagileproject managementproject management toolsagile managementpaginationpagingaspnetapp devkotlinandroid tutorialappsandroid content providersjavaframeworkjsfgrailsstruts 2core java video tutorialsbest books for java beginnersexport preview templatemultichannel previewmultichannel preview in pimpreview templatejavascriptangularjsangularwebdevandroiddevlifecyclepythonpython librarytensorflowscrapywordpressbloggingnodejsangularjsvpcawsvpc peeringprivate networkvirtual private networktop nodejs toolseffective nodejs toolsjavascriptreactjsangularjsaureliaphpsublimeeclipsenetbeansidesemberjsreactjsphplaravelandroid devandroid application devcprogrammingprogramming languagessvghtml5