- Angular Tutorial
- Angular - Home
- Angular - Overview
- Angular - Features
- Angular - Advantages & Disadvantages
- Angular Basics
- Angular - Environment setup
- Angular - First Application
- Angular - MVC Architecture
- Angular Components
- Angular - Components
- Angular - Component Lifecycle
- Angular - View Encapsulation
- Angular - Emulated Encapsulation
- Angular - ShadowDom Encapsulation
- Angular - Component Interaction
- Angular - Using @Input Decorator
- Angular - Using @Output Decorator
- Angular - Using Local Variable
- Angular - Using @ViewChild Decorator
- Angular - Using Services
- Angular - Component Styles
- Angular - Nested Components
- Angular - Content projection
- Angular - Single-slot Content Projection
- Angular - Multi-slot Content Projection
- Angular - Conditional Content Projection
- Angular - Dynamic components
- Angular - Using NgComponentOutlet
- Angular - Using ViewContainerRef
- Angular - Elements
- Angular Templates
- Angular - Templates
- Angular - Template statements
- Angular - Template Variables
- Angular - SVG as Templates
- Angular Binding
- Angular - Data Binding
- Angular - Interpolation
- Angular - Event Binding
- Angular - Property Binding
- Angular - Attribute Binding
- Angular - Class Binding
- Angular - Style Binding
- Angular - Two-way Binding
- Angular Directives
- Angular - Directives
- Angular - Attribute Directives
- Angular - Structural Directives
- Angular - Custom Directives
- Angular Pipes
- Angular - Pipes
- Angular - Built-in Pipes
- Angular - Custom Pipes
- Angular Forms
- Angular - Forms
- Angular - Template Driven Forms
- Angular - Reactive Forms
- Angular - Form Validation
- Angular - Dynamic Forms
- Angular Dependency Injection
- Angular - Dependency Injection
- Angular - Injectable Service
- Angular Routing
- Angular - Routing
- Angular - Dynamic Routes
- Angular - Wildcard Routes
- Angular - Nested Routes
- Angular - Navigation
- Angular - Routing in SPA
- Angular - Custom Route Matches
- Angular - Router Reference
- Angular HTTP Client programming
- Angular - Services
- Angular - HTTP Client
- Angular - Express based REST API
- Angular - Request
- Angular - Request Response Workflow
- Angular - Response
- Angular - Express based Upload API
- Angular - GET
- Angular - POST
- Angular - PUT
- Angular - DELETE
- Angular - JSONP
- Angular - CRUD Operations Using HTTP
- Angular Modules
- Angular - Introduction to Modules
- Angular - Root Module
- Angular - Feature Module
- Angular - Sharing Module
- Angular - Routing Module
- Angular - NgModules
- Angular Animation
- Angular - Animations
- Angular Service Workers & PWA
- Angular - Service Workers & PWA
- Angular Testing
- Angular - Testing Overview
- Angular Design Patterns
- Angular - Design Patterns
- Angular - Lazy Loading
- Angular - Singleton Pattern
- Angular - Observer Pattern
- Angular Libraries
- Angular - Libraries
- Angular - Angular Material
- Angular - PrimeNG
- Angular - RxJS
- Angular Advanced
- Angular - Signals
- Angular - Authentication & Authorization
- Angular - Internationalization
- Angular - Standalone Component
- Angular - Accessibility
- Angular - Web Workers
- Angular - Server Side Rendering
- Angular - Ivy Compiler
- Angular - Building with Bazel
- Angular - Backward Compatibility
- Angular - Reactive Programming
- Angular Tools
- Angular - CLI
- Angular Material UI Elements
- Angular - Paginator
- Angular - Datepicker
- Angular - Select Drop-down
- Angular Miscellaneous
- Angular - Third Party Controls
- Angular - Configuration
- Angular - Displaying Data
- Angular - Decorators & Metadata
- Angular - Basic Example
- Angular - Error Handling
- Angular - Testing & Building a Project
- Angular - Lifecycle Hooks
- Angular - User Input
- Angular - What's New?
- Angular Useful Resources
- Angular - Quick Guide
- Angular - Useful Resources
- Angular - Discussion
Angular - Binding & it's Types
Binding is the process of connecting a target in the template to a template expression or template statement created from model of the component to which the template belongs. When the model of the component changes, then output of the template expression changes and it updates the template output (view) as well.
Type of Binding
Text interpolation is the simplest form of binding and angular provides many types of binding for different scenarios. The type of binding are as follows −
- Text interpolation
- Attribute binding
- Class binding
- Style binding
- Property binding
- Event binding
- Two way data binding
Text interpolation
Text interpolation is the process of connecting model of a components instance to the text portion of components template.
Let us consider a property, name available in the component.
name: string = "John"
Then, the name can be used in the template using text interpolation as shown below −
Name: {{ name }}
The final output of the template is shown below −
Name: John
Let us learn text interpolation in details in the upcoming chapter.
Attribute binding
Attribute binding is the process of connecting model of a components instance to the attribute of a (target) HTML element in the components template
Let us consider a property, name available in the component.
name: string = "John"
Attribute binding can be written as shown below −
<input type="text" name="username" [attr.value]="name" />
The output of the template is shown below −
<input type="text" name="username" value="John" />
Let us learn attribute in details in the upcomming chapter.
Style binding
Style binding is the process of connecting model of a components instance to the style attributes of a (target) HTML element in the components template
Let us consider a property, myStyle available in the component.
myStyle: string = "background-color: blue"
Class binding can be written as shown below −
<button [style]="myStyle">Click here</button>
The output of the template is shown below −
<button style="background-color: blue">Click here</button>
Let us learn style binding in details in the upcomming chapter.
Class binding
Class binding is the process of connecting model of a components instance to the class attributes of a (target) HTML element in the components template
Let us consider a property, myClass available in the component.
myClass: string = "fancy-button"
Class binding can be written as shown below −
<button [class]="myClass">Click here</button>
The output of the template is shown below −
<button class="fancy-button">Click here</button>
Let us learn class binding concept in details in the upcoming chapter.
Property binding
Property binding is the process of connecting model of a components instance to the property of a (target) HTML element / other component in the components template. Angular exposes the attributes of HTML element as properties with attribute names converted to CamelCase. This will help to connect all attributes of the HTML element through property binding.
Let us consider a property, name available in the component.
name: string = "John"
Property binding can be written as shown below −
<input type="text" name="username" [value]="name" />
The output of the template is shown below −
<input type="text" name="username" value="John" />
Let us learn property binding concept in details in the upcoming chapter.
Event binding
Event binding is the process of setting an action (template statements / components method) to the event of a (target) HTML element / (another) component.
Let us consider a method, myAction available in the component.
myAction() {
// do some process
}
Event binding can be written as shown below −
<button type="submit" (submit)="myAction">Click here</button>
Once the submit event is fired, myAction() method will be called and executed.
Let us learn event binding concept in details in the upcoming chapter.
Two way data binding
Two way data binding is a combination of property and event binding to sync data between parent and child component.
A sample two-way data binding format is as follows −
// `parent-comp` template <child-comp [(data)]="dataChange()" />
Here, data will be passed initially from parent to child component and then, whenever the data gets updated in the child component, the child component will fire an event with updated data and the parent will capture the data through event callback method, dataChange().
Let us learn two-way data binding concept in details in the upcoming chapter.
Conclusion
Binding provides multiple options to connect a component to its template. This enables the developer to create rich frontend application easily. Binding reduces the complexity of frontend logic and enable developer to concentrate on developing more feature in a short period of time.