YogeshChauhan . com

Angular: Templates, directives, data binding, Services and dependency injection

in Angular on May 9, 2020

Introduction to Angular concepts Part 2

Templates directives

A template combines HTML with Angular markup that can modify HTML elements before they are displayed.

Template directives provide program logic.

Data binding

Binding markup connects your application data and the DOM.

There are two types of data binding:

1. Event Binding

2. Property Binding

Event binding lets your app respond to user input in the target environment by updating your application data.

Property binding lets you interpolate values that are computed from your application data into the HTML.

Angular evaluates the directives before a view is displayed.

It resolves the binding syntax in the template to modify the HTML elements and the DOM, according to your program data and logic.

Angular supports two-way data binding, meaning that changes in the DOM, such as user choices, are also reflected in your program data.

Your templates can use pipes to improve the user experience by transforming values for display.

For example, use pipes to display dates and currency values that are appropriate for a user’s locale.

Angular provides predefined pipes for common transformations, and you can also define your own pipes.


You create a service class for the data or logic that isn’t associated with a specific view, and that you want to share across components.

A service class definition is immediately preceded by the @Injectable() decorator.

The decorator provides the metadata that allows other providers to be injected as dependencies into your class.

Dependency injection

Dependency injection (DI) lets you keep your component classes lean and efficient by delegating tasks to services.

They don’t fetch data from the server, validate user input, or log directly to the console.

They delegate such tasks to services.

Credit: Angular.io


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

How to get current timestamp in Swift 4 and 5?SwiftSequence generator (range) using JavaScript Array.from()JavaScriptShould we ever delete data from a database?MiscHow to retrieve homepage URL in WordPress?WordPressAvoid using new Array() in JavaScriptJavaScriptSteps to Secure a VPNMisc