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
pythonpython librarytensorflowscrapymagento pluginsmagento extensionsandroidandroid appsandroid tutorialandroid componentiotiot in businessdynamics 365microsoft dynamics axandroid devandroid application devexport preview templatemultichannel previewmultichannel preview in pimpreview templatesvghtml5artificial intelligencebusinesssmall businessjavascriptangularjsangularwebdevnodejstop nodejs toolseffective nodejs toolsjavascriptangularjsemberjsreactjsaureliaphpcmsdrupalweb developmentvpcawsvpc peeringprivate networkvirtual private networkappsandroid content providersmagentoecommerceshopifywoocommerceopencartwordpresswebsite templatewebmasterswebsite designiosswiftandroiddevtechnologylifecyclesublimeeclipsenetbeansidescore java video tutorialsbest books for java beginnerscakephpcakephp 2 vs cakephp 3informaticamdmdatabasedata integrationphplaravelreactjsangularjs