Yogesh Chauhan's Blog

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.

Services

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 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to enable and disable button using JavaScript?JavaScript@forward rule in SCSS (Sass)SCSSThe actual difference between indexOf() and search() in JavaScriptJavaScriptHow to add CurrencyPipe in TypeScript file in Angular 9 Project?AngularSelf-Driving and Intelligent NetworksMiscellaneousHow to change CSS with JavaScript?CSS