Introduction
Here, I am going to discuss the AngularStyle Binding with examples. Setting inline styles with style binding is very similar to setting CSS classes with class binding. So, please read the class binding in Angular article before proceeding with this one.
- Interpolation Data Binding in Angular
- Property Data Binding in Angular
- Class Data Binding in Angular
What is style binding in Angular?
Style data binging is used to set the style in View's HTML elements. We can use the inline style to set the style in the element. We can also set inline style using style binding in Angular.
What is the difference between style binding and class binding?
Style binding is used to set a style of a View element. We can set inline styles with style binding.
- <h1 [style.font-size.px]="fontSize">Welcome to Angular</h1>
Class binding is used to set a class property of a View element. We can add and remove the CSS class names from an element's class attribute with class binding.
- <h1 [class]="myClass">Welcome to Angular</h1>
Step 1
Open the command prompt from Windows search.
Step 2
Create a new project in Angular
ng new AngularDemo
Step 3
Open the project in Visual Studio Code and type the following command to open the project.
Code:
Step 4
Open terminal in Visual Studio Code and create a component "employee".
ng g c example
Step 5
Open the example component in your application.
- import { Component, OnInit } from '@angular/core';
- @Component({
- selector: 'app-example',
- templateUrl: './example.component.html',
- styleUrls: ['./example.component.css']
- })
- export class ExampleComponent {
- fontSize: number = 80;
- }



Amit MohantyPosted Jun 26, 2019, 2:10 AM
Good Job...