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
agileproject managementproject management toolsagile managementfrontendnodejsangularjshtmljavascriptandroidapp devkotlinandroid tutorialphplaravelwebdevjavascriptangularjsangularreactjsangularjsaureliacakephpcakephp 2 vs cakephp 3svghtml5phpsublimeeclipsenetbeansidesinformaticamdmdatabasedata integrationandroiddevtechnologylifecycleappsandroid content providersandroid tutorialmagento pluginsmagento extensionsmagentoecommerceshopifywoocommerceopencartandroid appsandroid componentjavaframeworkjsfgrailsstruts 2export preview templatemultichannel previewmultichannel preview in pimpreview templatenodejstop nodejs toolseffective nodejs toolsmagento developerscmsartificial intelligencebusinesssmall businesspaginationpagingaspnetmobile developmentmobile app developmentdevelopmentiotiot in businessdynamics 365microsoft dynamics axiosswift