SlideShare a Scribd company logo
Software IndustrySultan Ahmed Sagor
Angular 7
A framework for Presentation Layer
Software IndustrySultan Ahmed Sagor
Software IndustrySultan Ahmed Sagor
Angular Data Binding
Software IndustrySultan Ahmed Sagor
Angular Tutorial: Road Covered So Far
Software IndustrySultan Ahmed Sagor
What is Data Binding ?
Now we will discuss angular data binding
Software IndustrySultan Ahmed Sagor
What are Data Binding?
Data binding is a connection bridge between view and the business logic (view model)
of the application.
Software IndustrySultan Ahmed Sagor
Type of Data Binding
Now we will see types of data binding
Software IndustrySultan Ahmed Sagor
Type of Data Binding
Software IndustrySultan Ahmed Sagor
Interpolation
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'Angular 7'; // declared array of months.
months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
isavailable = true; //variable is set to true
}
Software IndustrySultan Ahmed Sagor
Interpolation
<!--The content below is only a placeholder and can be replaced.-->
<div style = "text-align:center">
<h1> Welcome to {{title}}. </h1>
</div>
<div> Months :
<select> <option *ngFor = "let i of months">{{i}}</option> </select>
</div> <br/>
<div>
<span *ngIf = "isavailable; else condition1">Condition is valid.</span>
<ng-template #condition1>Condition is invalid</ng-template>
</div>
Software IndustrySultan Ahmed Sagor
Interpolation
Software IndustrySultan Ahmed Sagor
Type of Data Binding
Software IndustrySultan Ahmed Sagor
Property Binding
❖ In Angular 7, property binding is used to pass data from the component class (component.ts) and
setting the value of the given element in the user-end (component.html).
❖ Property binding is an example of one-way databinding where the data is transferred from the
component to the class.
❖ The main advantage of property binding is that it facilitates you to control elements property.
Software IndustrySultan Ahmed Sagor
Property Binding
❖ Now we will see property binding in action.
❖ imageUrl:string = '../../assets/logo.png' ;
❖ <img [src]="imageUrl" alt="">
❖ We will see same thing as like as before.
Software IndustrySultan Ahmed Sagor
Property Binding
Software IndustrySultan Ahmed Sagor
Type of Data Binding
Software IndustrySultan Ahmed Sagor
Event Binding
❖ When a user interacts with an application it generates an event .
❖ Some examples of the events are:
❖ keyboard movement,
❖ a mouse click
❖ a mouseover
❖ These events need to be handled to perform some kind of action.
❖ This is where event binding comes into picture.
❖ Now we will see event binding in real life example.
Software IndustrySultan Ahmed Sagor
Event Binding
❖ Let us generate a component by the following command.
❖ In databind.component.html file type in the following code.
❖ We will see a textbox in the browser.
ng g c databind
<input type=”text” value=”MagnetBrains” />
Software IndustrySultan Ahmed Sagor
Event Binding
❖ Let us generate a component by the following command.
❖ In databind.component.html file type in the following code.
❖ We will see a textbox in the browser.
ng g c databind
<input type=”text” value=”MagnetBrains” />
Software IndustrySultan Ahmed Sagor
Event Binding
❖ we have to do the event binding so update the following code indatabind.component.html file.
❖ In databind.component.ts file write up the following code to define the function showvalue() –
❖ After this again click on input box and you would notice events being passed on console tab.
<input type=”text” value=”MagnetBrains” (click)="showvalue($event)" />
showvalue(event){
console.log(“event”);
}
Software IndustrySultan Ahmed Sagor
Event Binding
❖ Let pass values from presentation layer (view) to component.
❖ Now we will see the log message in the console when we will click the textbox.
showvalue(event){
console.log('event.target.value');
}
Software IndustrySultan Ahmed Sagor
Type of Data Binding
Software IndustrySultan Ahmed Sagor
2 Way Data binding
❖ Two-way data binding in Angular will help users to exchange data from the component to view and
from view to the component.
❖ It will help users to establish communication bi-directionally.
❖ Two-way data binding can be achieved using a ngModel directive in Angular.
❖ The below syntax shows the data binding using (ngModel),
Software IndustrySultan Ahmed Sagor
2 Way Data binding
❖ Let us define a text box :
❖ Corresponding business logic may be as following:
<h2>Two-way Binding Example</h2>
<input [(ngModel)]="fullName" /> <br/><br/>
<p> {{fullName}} </p>
export class AppComponent {
fullName: string = "Hello JavaTpoint";
}
Software IndustrySultan Ahmed Sagor
2 Way Data binding
Software IndustrySultan Ahmed Sagor
Interpolation & Event Binding
Software IndustrySultan Ahmed Sagor
Parent to Child Component
❖ In this situation, the parent component has a message.
❖ Let us pass this message to child component, in the child component HTML, displaying the message:
❖ So call the child component like as following:
parentMessage:string = 'Data is passing' ;
<app-heroes [message]='parentMessage'></app-heroes>
Software IndustrySultan Ahmed Sagor
Parent to Child Component
❖ The child components typescript class must have to change like as following:
❖ Now print the message from child components view file:
@Input() message;
<p>{{message}}</p>
Software IndustrySultan Ahmed Sagor
Any
question?
Software IndustrySultan Ahmed Sagor
Thank You

More Related Content

PDF
Angular Dependency Injection
PPTX
Angular Data Binding
PPTX
Angular 2.0 forms
PDF
Angular - Chapter 4 - Data and Event Handling
ODP
Routing & Navigating Pages in Angular 2
PPTX
Sharing Data Between Angular Components
PPTX
Angular Data Binding
PPT
Angular Introduction By Surekha Gadkari
Angular Dependency Injection
Angular Data Binding
Angular 2.0 forms
Angular - Chapter 4 - Data and Event Handling
Routing & Navigating Pages in Angular 2
Sharing Data Between Angular Components
Angular Data Binding
Angular Introduction By Surekha Gadkari

What's hot (20)

PPTX
Angularjs PPT
PDF
Angular Directives
PPTX
Angular 9
PDF
Angular - Chapter 7 - HTTP Services
PDF
Angular Advanced Routing
PDF
Angular Observables & RxJS Introduction
PPTX
Object Oriented Programming In JavaScript
PDF
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
PDF
Angular components
PDF
Angular - Chapter 5 - Directives
PPTX
Introduction to angular with a simple but complete project
PPTX
PDF
Ngrx slides
PPTX
Angular 14.pptx
PPT
Vue.js Getting Started
PDF
Angular routing
PDF
Basics of JavaScript
PDF
An introduction to Vue.js
PPTX
Angular modules in depth
PDF
Javascript basics
Angularjs PPT
Angular Directives
Angular 9
Angular - Chapter 7 - HTTP Services
Angular Advanced Routing
Angular Observables & RxJS Introduction
Object Oriented Programming In JavaScript
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular components
Angular - Chapter 5 - Directives
Introduction to angular with a simple but complete project
Ngrx slides
Angular 14.pptx
Vue.js Getting Started
Angular routing
Basics of JavaScript
An introduction to Vue.js
Angular modules in depth
Javascript basics
Ad

Similar to Angular data binding (20)

PDF
Angular 4 Data Binding | Two Way Data Binding in Angular 4 | Angular 4 Tutori...
PPTX
Data binding in Angular fully Explained .pptx
PDF
What is data binding in Angular
PDF
New Angular project and created a component.
PDF
Angular 2 overview in 60 minutes
PPTX
angular-concepts-introduction-slides.pptx
PPTX
Data Sharing Between Child and Parent Components in AngularJS
PDF
Itroducing Angular JS
PPTX
Data Binding for Xamarin Forms In-Depth
PPTX
Building a TV show with Angular, Bootstrap, and Web Services
PDF
Angular Project Report
PDF
Data Binding and Forms in Angular 2
PPT
17612235.ppt
PPTX
Presentation on angular 5
PDF
Angular Interview Questions-PDF.pdf
PDF
Angular2 Development for Java developers
KEY
WPF Binding
PDF
Angular2 with type script
DOCX
Angular Interview Questions & Answers
PDF
Building Powerful Applications with AngularJS 2 and TypeScript - David Giard
Angular 4 Data Binding | Two Way Data Binding in Angular 4 | Angular 4 Tutori...
Data binding in Angular fully Explained .pptx
What is data binding in Angular
New Angular project and created a component.
Angular 2 overview in 60 minutes
angular-concepts-introduction-slides.pptx
Data Sharing Between Child and Parent Components in AngularJS
Itroducing Angular JS
Data Binding for Xamarin Forms In-Depth
Building a TV show with Angular, Bootstrap, and Web Services
Angular Project Report
Data Binding and Forms in Angular 2
17612235.ppt
Presentation on angular 5
Angular Interview Questions-PDF.pdf
Angular2 Development for Java developers
WPF Binding
Angular2 with type script
Angular Interview Questions & Answers
Building Powerful Applications with AngularJS 2 and TypeScript - David Giard
Ad

Recently uploaded (20)

PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
web development for engineering and engineering
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Lecture Notes Electrical Wiring System Components
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
composite construction of structures.pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
Welding lecture in detail for understanding
PDF
Well-logging-methods_new................
PPT
Project quality management in manufacturing
PPTX
Construction Project Organization Group 2.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
web development for engineering and engineering
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Lecture Notes Electrical Wiring System Components
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Foundation to blockchain - A guide to Blockchain Tech
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
composite construction of structures.pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Lesson 3_Tessellation.pptx finite Mathematics
Welding lecture in detail for understanding
Well-logging-methods_new................
Project quality management in manufacturing
Construction Project Organization Group 2.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx

Angular data binding

  • 1. Software IndustrySultan Ahmed Sagor Angular 7 A framework for Presentation Layer
  • 3. Software IndustrySultan Ahmed Sagor Angular Data Binding
  • 4. Software IndustrySultan Ahmed Sagor Angular Tutorial: Road Covered So Far
  • 5. Software IndustrySultan Ahmed Sagor What is Data Binding ? Now we will discuss angular data binding
  • 6. Software IndustrySultan Ahmed Sagor What are Data Binding? Data binding is a connection bridge between view and the business logic (view model) of the application.
  • 7. Software IndustrySultan Ahmed Sagor Type of Data Binding Now we will see types of data binding
  • 8. Software IndustrySultan Ahmed Sagor Type of Data Binding
  • 9. Software IndustrySultan Ahmed Sagor Interpolation import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'Angular 7'; // declared array of months. months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; isavailable = true; //variable is set to true }
  • 10. Software IndustrySultan Ahmed Sagor Interpolation <!--The content below is only a placeholder and can be replaced.--> <div style = "text-align:center"> <h1> Welcome to {{title}}. </h1> </div> <div> Months : <select> <option *ngFor = "let i of months">{{i}}</option> </select> </div> <br/> <div> <span *ngIf = "isavailable; else condition1">Condition is valid.</span> <ng-template #condition1>Condition is invalid</ng-template> </div>
  • 11. Software IndustrySultan Ahmed Sagor Interpolation
  • 12. Software IndustrySultan Ahmed Sagor Type of Data Binding
  • 13. Software IndustrySultan Ahmed Sagor Property Binding ❖ In Angular 7, property binding is used to pass data from the component class (component.ts) and setting the value of the given element in the user-end (component.html). ❖ Property binding is an example of one-way databinding where the data is transferred from the component to the class. ❖ The main advantage of property binding is that it facilitates you to control elements property.
  • 14. Software IndustrySultan Ahmed Sagor Property Binding ❖ Now we will see property binding in action. ❖ imageUrl:string = '../../assets/logo.png' ; ❖ <img [src]="imageUrl" alt=""> ❖ We will see same thing as like as before.
  • 15. Software IndustrySultan Ahmed Sagor Property Binding
  • 16. Software IndustrySultan Ahmed Sagor Type of Data Binding
  • 17. Software IndustrySultan Ahmed Sagor Event Binding ❖ When a user interacts with an application it generates an event . ❖ Some examples of the events are: ❖ keyboard movement, ❖ a mouse click ❖ a mouseover ❖ These events need to be handled to perform some kind of action. ❖ This is where event binding comes into picture. ❖ Now we will see event binding in real life example.
  • 18. Software IndustrySultan Ahmed Sagor Event Binding ❖ Let us generate a component by the following command. ❖ In databind.component.html file type in the following code. ❖ We will see a textbox in the browser. ng g c databind <input type=”text” value=”MagnetBrains” />
  • 19. Software IndustrySultan Ahmed Sagor Event Binding ❖ Let us generate a component by the following command. ❖ In databind.component.html file type in the following code. ❖ We will see a textbox in the browser. ng g c databind <input type=”text” value=”MagnetBrains” />
  • 20. Software IndustrySultan Ahmed Sagor Event Binding ❖ we have to do the event binding so update the following code indatabind.component.html file. ❖ In databind.component.ts file write up the following code to define the function showvalue() – ❖ After this again click on input box and you would notice events being passed on console tab. <input type=”text” value=”MagnetBrains” (click)="showvalue($event)" /> showvalue(event){ console.log(“event”); }
  • 21. Software IndustrySultan Ahmed Sagor Event Binding ❖ Let pass values from presentation layer (view) to component. ❖ Now we will see the log message in the console when we will click the textbox. showvalue(event){ console.log('event.target.value'); }
  • 22. Software IndustrySultan Ahmed Sagor Type of Data Binding
  • 23. Software IndustrySultan Ahmed Sagor 2 Way Data binding ❖ Two-way data binding in Angular will help users to exchange data from the component to view and from view to the component. ❖ It will help users to establish communication bi-directionally. ❖ Two-way data binding can be achieved using a ngModel directive in Angular. ❖ The below syntax shows the data binding using (ngModel),
  • 24. Software IndustrySultan Ahmed Sagor 2 Way Data binding ❖ Let us define a text box : ❖ Corresponding business logic may be as following: <h2>Two-way Binding Example</h2> <input [(ngModel)]="fullName" /> <br/><br/> <p> {{fullName}} </p> export class AppComponent { fullName: string = "Hello JavaTpoint"; }
  • 25. Software IndustrySultan Ahmed Sagor 2 Way Data binding
  • 26. Software IndustrySultan Ahmed Sagor Interpolation & Event Binding
  • 27. Software IndustrySultan Ahmed Sagor Parent to Child Component ❖ In this situation, the parent component has a message. ❖ Let us pass this message to child component, in the child component HTML, displaying the message: ❖ So call the child component like as following: parentMessage:string = 'Data is passing' ; <app-heroes [message]='parentMessage'></app-heroes>
  • 28. Software IndustrySultan Ahmed Sagor Parent to Child Component ❖ The child components typescript class must have to change like as following: ❖ Now print the message from child components view file: @Input() message; <p>{{message}}</p>
  • 29. Software IndustrySultan Ahmed Sagor Any question?
  • 30. Software IndustrySultan Ahmed Sagor Thank You