Component Communication in Angular
Last Updated :
23 Jul, 2025
Angular, as a robust front-end framework, allows you to build complex and interactive web applications by creating reusable components. One of the key aspects of building such applications is effective communication between these components.
There are a lot of instances where we need to transfer data and events between angular components.
The communication can be between parent and child components or between sibling components. We will try out 3 methods to transfer data on our angular application.
Steps to create an Angular application:
Step 1: Create an angular application using the following command.
ng new angular-com
Make sure angular is already installed in your system.
Step 2: Go inside the angular project
cd angular-com
Step 3: Next, we will run the application through the below command
ng serve --open
Step 4: Create the required component to share data between them.
ng generate component comp-alpha
ng generate component comp-beta
Folder Structure:
The updated Dependencies in package.json file will look like:
"dependencies": {
"@angular/animations": "^17.3.0",
"@angular/common": "^17.3.0",
"@angular/compiler": "^17.3.0",
"@angular/core": "^17.3.0",
"@angular/forms": "^17.3.0",
"@angular/platform-browser": "^17.3.0",
"@angular/platform-browser-dynamic": "^17.3.0",
"@angular/router": "^17.3.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
}
Now, that we have our component created, we will proceed with adding some boilerplate code. You can add code in the following components to have our initial code ready. Add the code for the app component as in the below editor
HTML
<!-- app.component.html -->
<div style="
display: flex;
background-color: aqua;
padding: 1rem;
/* height: 20rem; */
flex-direction: column;
">
<div style="display: flex; flex-direction: column; justify-content: center">
<div style="display: flex; justify-content: center">
This is parent component
</div>
<div style="display: flex; justify-content: center">
<p>
<input type="text" name="homeText" id="homeText" [(ngModel)]="homeText" />
</p>
</div>
<div style="display: flex; justify-content: center">
Your Text - <b>{{ homeText }}</b>
</div>
<div style="display: flex; justify-content: center">
<p>
<button style="margin-right: 1rem">Pass to alpha component</button>
<button>Pass to beta component</button>
</p>
</div>
</div>
<div style="display: flex; flex-direction: row; justify-content: center">
<app-comp-alpha></app-comp-alpha>
<app-comp-beta></app-comp-beta>
</div>
</div>
HTML
<!-- comp-alpha.component.html -->
<div style="
display: flex;
background-color: lightgreen;
padding: 1rem;
height: 10rem;
flex-direction: column;
margin: 2rem;
">
<div style="display: flex; flex-direction: row; justify-content: center">
This is alpha component
</div>
<div style="display: flex; flex-direction: column; justify-content: center">
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
<input type="text" name="alpaText" id="alphaText" [(ngModel)]="alphaText" />
</div>
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
Your Text - <b>{{ alphaText }}</b>
</div>
<div style="display: flex; flex-direction: row">
<div style="margin-left: 0.6rem; margin-right: 0.3rem">
<button>Pass to parent component</button>
</div>
<div style="margin-right: 0.6rem; margin-left: 0.3rem">
<button>Pass to beta component</button>
</div>
</div>
</div>
</div>
HTML
<!-- comp-beta.component.ts -->
<div style="
display: flex;
background-color: lightpink;
padding: 1rem;
height: 10rem;
flex-direction: column;
margin: 2rem;
">
<div style="display: flex; flex-direction: row; justify-content: center">
This is beta component
</div>
<div style="display: flex; flex-direction: column; justify-content: center">
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
<input type="text" name="alpaText" [(ngModel)]="betaText" id="betaText" />
</div>
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
Your Text - <b>{{ betaText }}</b>
</div>
<div style="display: flex; flex-direction: row">
<div style="margin-left: 0.6rem; margin-right: 0.3rem">
<button>Pass to parent component</button>
</div>
<div style="margin-right: 0.6rem; margin-left: 0.3rem">
<button>Pass to alpha component</button>
</div>
</div>
</div>
</div>
JavaScript
//app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
title = 'angular-com';
homeText = 'Hello parent!';
}
JavaScript
//app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { CompAlphaComponent } from './comp-alpha/comp-alpha.component';
import { CompBetaComponent } from './comp-beta/comp-beta.component';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [AppComponent, CompAlphaComponent, CompBetaComponent],
imports: [BrowserModule, AppRoutingModule, FormsModule],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule { }
JavaScript
//comp-alpha.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-comp-alpha',
templateUrl: './comp-alpha.component.html',
styleUrls: ['./comp-alpha.component.css'],
})
export class CompAlphaComponent implements OnInit {
constructor() { }
alphaText = 'Hello alpha!';
ngOnInit(): void { }
}
JavaScript
//comp-beta.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-comp-beta',
templateUrl: './comp-beta.component.html',
styleUrls: ['./comp-beta.component.css'],
})
export class CompBetaComponent implements OnInit {
constructor() { }
betaText = 'Hello beta!';
ngOnInit(): void { }
}
Output:
Demo page
The blue background represents the parent component with two child components - alpha and beta. Next, we will be working on how to pass values and events through parent and child components and in between child components.
In angular, we use input bindings to pass data from parent to child components. In our example code above, we will pass data from the app component to the alpha component by using an input decorator. Consider the following code changes -
HTML
<!--comp-alpha.component.html-->
<div style="
display: flex;
background-color: lightgreen;
padding: 1rem;
height: 20rem;
flex-direction: column;
margin: 2rem;
">
<div style="display: flex; flex-direction: row; justify-content: center">
This is alpha component
</div>
<div style="display: flex; flex-direction: column; justify-content: center">
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
<input type="text" name="alpaText" id="alphaText" [(ngModel)]="alphaText" />
</div>
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
Your Text - <b>{{ alphaText }}</b>
</div>
<div style="display: flex; flex-direction: row">
<div style="margin-left: 0.6rem; margin-right: 0.3rem">
<button>Pass to parent component</button>
</div>
<div style="margin-right: 0.6rem; margin-left: 0.3rem">
<button>Pass to beta component</button>
</div>
</div>
<div style="display: flex; flex-direction: column; padding: 0.5rem">
<div style="padding-top: 0.5rem; padding-bottom: 0.5rem">
<b>Whatever you see below is coming from parent component</b>
</div>
<div>{{ parentText }}</div>
</div>
</div>
</div>
HTML
<!--app.component.html-->
<div style="
display: flex;
background-color: aqua;
padding: 1rem;
/* height: 20rem; */
flex-direction: column;
">
<div style="display: flex; flex-direction: column; justify-content: center">
<div style="display: flex; justify-content: center">
This is parent component
</div>
<div style="display: flex; justify-content: center">
<p>
<input type="text" name="homeText" id="homeText" [(ngModel)]="homeText" />
</p>
</div>
<div style="display: flex; justify-content: center">
Your Text - <b>{{ homeText }}</b>
</div>
<div style="display: flex; justify-content: center">
<p>
<button style="margin-right: 1rem">Pass to alpha component</button>
<button>Pass to beta component</button>
</p>
</div>
</div>
<div style="display: flex; flex-direction: row; justify-content: center">
<app-comp-alpha [textFromParent]="homeText"></app-comp-alpha>
<app-comp-beta></app-comp-beta>
</div>
</div>
JavaScript
//comp-alpha.component.ts
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'app-comp-alpha',
templateUrl: './comp-alpha.component.html',
styleUrls: ['./comp-alpha.component.css'],
})
export class CompAlphaComponent implements OnInit {
constructor() { }
alphaText = 'Hello alpha!';
ngOnInit(): void { }
@Input('textFromParent') parentText = '';
}
Output:
Passing values from parent to child component
Here, we are using @Input() decorator to bind the property we want to pass from parent to child. In the comp-alpha.component.ts, we have added the following code
@Input('textFromParent') parentText = '';
And, in the app.component.html, we are passing the value to this property -
<app-comp-alpha [textFromParent]="homeText"></app-comp-alpha>
2. Listening to events from the child component in the parent component
In the previous method, we passed values from parent to child. To listen to any event happening in the child component like - button-click, saving completion, page load, etc., we will use an event listener to accomplish this.
Consider below changes in code -
HTML
<!--comp-beta.component.html -->
<div style="
display: flex;
background-color: lightpink;
padding: 1rem;
height: 20rem;
flex-direction: column;
margin: 2rem;
">
<div style="display: flex; flex-direction: row; justify-content: center">
This is beta component
</div>
<div style="display: flex; flex-direction: column; justify-content: center">
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
<input type="text" name="alpaText" [(ngModel)]="betaText" id="betaText" />
</div>
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
Your Text - <b>{{ betaText }}</b>
</div>
<div style="display: flex; flex-direction: row">
<div style="margin-left: 0.6rem; margin-right: 0.3rem">
<button (click)="passToParent()">Pass to parent component</button>
</div>
<div style="margin-right: 0.6rem; margin-left: 0.3rem">
<button>Pass to alpha component</button>
</div>
</div>
</div>
</div>
HTML
<!--app.component.html -->
<div style="
display: flex;
background-color: aqua;
padding: 1rem;
/* height: 20rem; */
flex-direction: column;
">
<div style="display: flex; flex-direction: column; justify-content: center">
<div style="display: flex; justify-content: center">
This is parent component
</div>
<div style="display: flex; justify-content: center">
<p>
<input type="text" name="homeText" id="homeText" [(ngModel)]="homeText" />
</p>
</div>
<div style="display: flex; justify-content: center">
Your Text - <b>{{ homeText }}</b>
</div>
<div style="display: flex; justify-content: center">
<p>
<button style="margin-right: 1rem">Pass to alpha component</button>
<button>Pass to beta component</button>
</p>
</div>
</div>
<div style="display: flex; flex-direction: column; justify-content: center">
<div style="display: flex; justify-content: center">Child event Log:</div>
<div *ngFor="let ev of evList" style="display: flex; justify-content: center">
{{ ev }}
</div>
</div>
<div style="display: flex; flex-direction: row; justify-content: center">
<app-comp-alpha [textFromParent]="homeText"></app-comp-alpha>
<app-comp-beta (childButtonClicked)="childButtonClicked($event)"></app-comp-beta>
</div>
</div>
JavaScript
//comp-beta.component.ts
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
@Component({
selector: 'app-comp-beta',
templateUrl: './comp-beta.component.html',
styleUrls: ['./comp-beta.component.css'],
})
export class CompBetaComponent implements OnInit {
constructor() { }
betaText = 'Hello beta!';
ngOnInit(): void { }
@Output() childButtonClicked = new EventEmitter<string>();
passToParent() {
this.childButtonClicked.emit('Button clicked in beta component');
}
}
JavaScript
//app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
title = 'angular-com';
homeText = 'Hello parent!';
evList: string[] = [];
childButtonClicked(event: string) {
this.evList.push(event);
}
}
To make this work, we first added an event emitter with @Output() decorator in comp-beta.component.ts. We added a method passToParent() to emit an event every time the button is clicked
@Output() childButtonClicked = new EventEmitter<string>();
passToParent() {
this.childButtonClicked.emit('Button clicked in beta component');
}
Next, in the app.component.html, we added a method to listen to the emitted event
<app-comp-beta (childButtonClicked)="childButtonClicked($event)"></app-comp-beta>
Every time, the event is emitted in the beta component, we add an array to string to display the event.
evList: string[] = [];
childButtonClicked(event: string) {
this.evList.push(event);
}
Output:
Event listening in a parent-from-child component3. Using Services to pass data between sibling component
Services can be used to pass data and components between parent and child components or between sibling components. We will take up an example to showcase how to pass values using services between child components.
We will create a service component to pass values. In the terminal, execute the following command -
ng generate service data-connect
It will create a service class file named data-connect.service.ts
Consider the following code changes -
HTML
<!--comp-alpha.component.html -->
<div style="
display: flex;
background-color: lightgreen;
padding: 1rem;
height: 20rem;
flex-direction: column;
margin: 2rem;
">
<div style="display: flex; flex-direction: row; justify-content: center">
This is alpha component
</div>
<div style="display: flex; flex-direction: column; justify-content: center">
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
<input type="text" name="alpaText" id="alphaText" [(ngModel)]="alphaText" />
</div>
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
Your Text - <b>{{ alphaText }}</b>
</div>
<div style="display: flex; flex-direction: row">
<div style="margin-left: 0.6rem; margin-right: 0.3rem">
<button>Pass to parent component</button>
</div>
<div style="margin-right: 0.6rem; margin-left: 0.3rem">
<button (click)="passToBeta()">Pass to beta component</button>
</div>
</div>
<div style="display: flex; flex-direction: column; padding: 0.5rem">
<div style="padding-top: 0.5rem; padding-bottom: 0.5rem">
<b>Whatever you see below is coming from parent component</b>
</div>
<div>{{ parentText }}</div>
</div>
<div style="display: flex; flex-direction: column; padding: 0.5rem">
<div style="padding-top: 0.5rem; padding-bottom: 0.5rem">
<b>Whatever you see below is coming from beta component</b>
</div>
<div>{{ dataService.getValue("alpha") }}</div>
</div>
</div>
</div>
HTML
<!-- comp-beta.component.html -->
<div style="
display: flex;
background-color: lightpink;
padding: 1rem;
height: 20rem;
flex-direction: column;
margin: 2rem;
">
<div style="display: flex; flex-direction: row; justify-content: center">
This is beta component
</div>
<div style="display: flex; flex-direction: column; justify-content: center">
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
<input type="text" name="alpaText" [(ngModel)]="betaText" id="betaText" />
</div>
<div style="
display: flex;
margin-top: 1rem;
margin-bottom: 1em;
justify-content: center;
">
Your Text - <b>{{ betaText }}</b>
</div>
<div style="display: flex; flex-direction: row">
<div style="margin-left: 0.6rem; margin-right: 0.3rem">
<button (click)="passToParent()">Pass to parent component</button>
</div>
<div style="margin-right: 0.6rem; margin-left: 0.3rem">
<button (click)="passToAlpha()">Pass to alpha component</button>
</div>
</div>
<div style="display: flex; flex-direction: column; padding: 0.5rem">
<div style="padding-top: 0.5rem; padding-bottom: 0.5rem">
<b>Whatever you see below is coming from alpha component</b>
</div>
<div>{{ dataService.getValue("beta") }}</div>
</div>
</div>
</div>
JavaScript
//data-connect.service.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class DataConnectService {
constructor() { }
alphaValue: string = 'This is default alpha value';
betaValue: string = 'This is default beta value';
setValue(comp: string, _value: string) {
if (comp === 'alpha') {
this.alphaValue = _value;
} else if (comp === 'beta') {
this.betaValue = _value;
}
}
getValue(comp: string) {
if (comp === 'alpha') {
return this.alphaValue;
} else if (comp === 'beta') {
return this.betaValue;
}
return 'No component given';
}
}
JavaScript
//comp-alpha.component.ts
import { Component, Input, OnInit } from '@angular/core';
import { DataConnectService } from '../data-connect.service';
@Component({
selector: 'app-comp-alpha',
templateUrl: './comp-alpha.component.html',
styleUrls: ['./comp-alpha.component.css'],
})
export class CompAlphaComponent implements OnInit {
constructor(public dataService: DataConnectService) { }
alphaText = 'Hello alpha!';
ngOnInit(): void { }
@Input('textFromParent') parentText = '';
passToBeta() {
this.dataService.setValue('beta', "Hey there! I'm alpha component");
}
}
JavaScript
//comp-beta.component.ts
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { DataConnectService } from '../data-connect.service';
@Component({
selector: 'app-comp-beta',
templateUrl: './comp-beta.component.html',
styleUrls: ['./comp-beta.component.css'],
})
export class CompBetaComponent implements OnInit {
constructor(public dataService: DataConnectService) { }
betaText = 'Hello beta!';
ngOnInit(): void { }
@Output() childButtonClicked = new EventEmitter<string>();
passToParent() {
this.childButtonClicked.emit('Button clicked in beta component');
}
passToAlpha() {
this.dataService.setValue('alpha', "Hey There! I'm beta");
}
}
In the data-connect.service.ts, we have created two variables to store values from the alpha and beta components respectively. Additionally, we have added two methods to get and set values of these two variables -
alphaValue: string = 'This is default alpha value';
betaValue: string = 'This is default beta value';
setValue(comp: string, _value: string) {
if (comp === 'alpha') {
this.alphaValue = _value;
} else if (comp === 'beta') {
this.betaValue = _value;
}
}
getValue(comp: string) {
if (comp === 'alpha') {
return this.alphaValue;
} else if (comp === 'beta') {
return this.betaValue;
}
return 'No component given';
}
We are injecting the service inside the alpha and beta components using the class constructor -
constructor(public dataService: DataConnectService) {}
We are calling the setter event when the button is clicked to set the value of the service variable as below -
passToBeta() {
this.dataService.setValue('beta', "Hey there! I'm alpha component");
}
Correspondingly, in the HTML component, we are getting the value using the following code -
<div>{{ dataService.getValue("alpha") }}</div>
The service we have declared is injected at the root level as declared in the component decorator meta-data.
@Injectable({
providedIn: 'root',
})
This means there is only one instance of service created at the root level and it is shared across all components. So any change in the service variable is reflected at all the places where the service is injected. So, this way, we can utilize the service for passing the data.
Output:
Passing data in between child components
Similar Reads
AngularJS Basics
AngularJS TutorialAngularJS is a free and open-source JavaScript framework that helps developers build modern web applications. It extends HTML with new attributes and it is perfect for single-page applications (SPAs). AngularJS, developed by Google, has been important in web development since its inception in 2009.
5 min read
Introduction to AngularJSAngularJS is a popular open-source framework that simplifies web development by creating interactive single-page applications (SPAs). Unlike traditional websites that load new pages for each click, SPAs offer a smoother user experience by updating content on the same page. AngularJS makes this possi
4 min read
Angular CLI | Angular Project SetupAngular is an open-source front-end web application framework that is used for building single-page and complex web applications. By default, angular uses TypeScript for creating logic but as the browser doesn't know typescript it converts typescript into javascript in order to make typescript under
3 min read
AngularJS ExpressionsIn this article, we will see the Expressions in AngularJS, along with understanding their implementation through the examples. Expressions in AngularJS are used to bind application data to HTML. The expressions are resolved by AngularJS and the result is returned back to where the expression is writ
2 min read
AngularJS ModulesThe AngularJS module defines the functionality of the application which is applied on the entire HTML page. It helps to link many components. So it is just a group of related components. It is a container that consists of different parts like controllers, services, and directives. Note: These module
3 min read
AngularJS ng-model DirectiveThe ngModel directive is a directive that is used to bind the values of the HTML controls (input, select, and textarea) or any custom form controls, and stores the required user value in a variable and we can use that variable whenever we require that value. It also is used during form validations.
4 min read
AngularJS Data BindingIn this article, we will see the Data Binding in AngularJS, along with understanding the various types of Data Binding available with their implementations. Angular provides a function Data Binding which helps us to have an almost real-time reflection of the input given by the user i.e. it creates a
4 min read
AngularJS ControllersIn this article, we will see the Controller in AngularJS along with knowing how Controller works, the concept of the Controller method & how the Controller can be implemented in an external. We will understand all these aspects with the help of their implementation & accordingly will its ill
3 min read
AngularJS | ScopeScope in AngularJS is the binding part of HTML view and JavaScript controller. When you add properties into the scope object in the JavaScript controller, only then the HTML view gets access to those properties. There are two types of Scope in AngularJS. $Scope$rootScope Scope: There is few specific
2 min read
AngularJS ServicesThe Services is a function or an object that avails or limit to the application in AngularJS, ie., it is used to create variables/data that can be shared and can be used outside the component in which it is defined. Service facilitates built-in service or can make our own service. The Service can on
4 min read
AngularJS | AJAX - $httpThe AngularJS provides a control service named as AJAX - $http, which serves the task for reading all the data that is available on the remote servers. The demand for the requirement of desired records gets met when the server makes the database call by using the browser. The data is mostly needed i
3 min read
AngularJS | TablesThe data in tables are basically repeatable, so you can use ng-repeat directives to create tables easily The example will clear the approach. Syntax: <element ng-repeat="expression">Content..<element> Displayed Data in table. html <!DOCTYPE html> <html> <head> <title
2 min read
AngularJS Select BoxesThe Select Boxes in AngularJS can be utilized to create dropdown lists, that are based on the objects or an array. The Select box can be created in 2 ways, i.e., either by using the ng-options directive that is used to build and bind HTML elements with options to model property or by using the ng-re
2 min read
AngularJS SQLIn any web application, we need to save, update, insert and fetch data to and from a database. AngularJS is a JavaScript MVC (Model-View-Controller) framework developed by Google. It helps developers to build well-structured, easily testable, and maintainable front-end applications. Important Featu
3 min read
AngularJS HTML DOMThe HTML DOM in AngularJS facilitates the directives that bind the application data with the attributes of HTML DOM elements. In this article, we will see such directives that help to bind the data to the HTML DOM element's attribute, along with their basic implementations through the illustrations.
2 min read
AngularJS EventsAn Events in AngularJS can be used to perform particular tasks, based on the action taken. Both Angular Event & the HTML Event will be executed & will not overwrite with an HTML Event. It can be added using the Directives mentioned below: ng-mousemove: The movement of the mouse leads to the
3 min read
AngularJS | FormsForms are collection of controls that is input field, buttons, checkbox and these can be validated real time. As soon as a user of the form completes writing a field and moves to the next one it gets validated and suggests the user where he might have went wrong. So a form can be consisting of the m
3 min read
AngularJS Form ValidationAngularJS performs form validation on the client side. AngularJS monitors the state of the form and input fields (input, text-area, select), and notify the user about the current state. AngularJS also holds information about whether the input fields have been touched, modified, or not. Form input fi
3 min read
AngularJS | APIAngularJS APIs are used for comparing, iterating and converting objects.Basic AngularJS API includes angular.isString() angular.lowercase() angular.uppercase() angular.isNumber() 1. angular.isString() It is used to check whether an object is a string or not.It returns true if the object is string ot
2 min read
AngularJS and W3.CSSWhat is W3.CSS? W3.CSS is a modern framework with built-in responsiveness and easy to learn and use compared to other CSS framework.Its aim is to speed up and simplify web development and support modern responsive devices like Mobile, Laptop, Tablet and DesktopW3.CSS was designed to be a high qualit
2 min read
AngularJS IncludesAngularJS includes, also called as ng-include directive, allows you to insert external HTML content dynamically into an AngularJS application. This capability is particularly useful for modularizing applications, improving code organization, and enhancing code reusability.Syntax:<element ng-inclu
3 min read
AngularJS AnimationsTo create animation effects in AngularJS using the ngAnimate module, which provides support for CSS-based animations. Animation is something that is used to give a dynamic motion effect. Here HTML is transformed to give an illusion of motion using the ngAnimate module that gives us a combined effect
1 min read
AngularJS | ApplicationApplications in AngularJS enable the creation of real-time Applications. There are four primary steps involved in creation of Applications in AngularJS: Creation of List for an Application. Adding elements in the List. Removing elements from the List. Error Handling Below are the steps for creations
3 min read
AngularJS Directives
AngularJS Filters
AngularJS | FiltersThere are some filters that are added in the AngularJS for the sake of making the formatting and working with data easier. There are several in-built filters in AngularJS. They are listed here along with some examples to make the understanding easier. Basic Syntax: Filters are generally added to the
7 min read
AngularJS currency FilterAngularJS currency filter is used to convert a number into a currency format. If no currency format is specified currency filter uses the local currency format. Syntax: {{ currency_expression | currency : symbol : fractionSize}}Parameters: It contains 2 parameters as mentioned above and described be
2 min read
AngularJS | date FilterAngularJS date filter is used to convert a date into a specified format. When the date format is not specified, the default date format is 'MMM d, yyyy'. Syntax: {{ date | date : format : timezone }} Parameter Values: The date filter contains format and timezone parameters which is optional.Some com
2 min read
AngularJS filter FilterThe "filter" Filter in AngularJS is used to filter the array and object elements and return the filtered items. In other words, this filter selects a subset (a smaller array containing elements that meet the filter criteria) of an array from the original array. Syntax: {{arrayexpression | filter: ex
3 min read
AngularJS json FilterThe json filter in AngularJs is used to convert a JavaScript object into a JSON. string.JavaScript object that we are using can be of any kind of JavaScript Object. The json filter piped the object or any expression with JSON so that the result will be displayed in the form of a list, which is bound
2 min read
AngularJS limitTo FilterThe limitTo filter in AngularJS is used to return an array or a string that contains a specified number of elements. This filter can be used with arrays, strings, and numbers. The basic principle, however, remains the same in all three cases: For arrays, it returns an array containing only the speci
2 min read
AngularJS lowercase FilterAngularJS provides different filters to format the data. The lowercase Filter formats the given string to the lowercase. In order to transmit & render the data from a TypeScript code to an HTML template (view), the interpolation concept can be utilized. The lowercase filter is piped with an expr
1 min read
AngularJS number FilterAngularJS number filter is used to convert a number into a string or text. We can also define a limit to display a number of decimal digits. The number filter rounds off the number to specified decimal digits. Syntax: {{ string| number : fractionSize}}Parameter Values: It contains single parameter v
1 min read
AngularJS orderBy FilterAn orderBy Filter in AngularJS is used to sort the given array to the specific order. The default order of sorting the string is in alphabetical order whereas the numbers are numerically sorted. By default, all the items are sorted in ascending order, if the ordering sequence is not specified. Synta
4 min read
AngularJs uppercase FilterThe uppercase Filter in AngularJS is used to change a string to an uppercase string or letters. Syntax: {{ string | uppercase}} Example: This example describes the use of the uppercase Filter in AngularJS. HTML <!DOCTYPE html> <html> <head> <title>uppercase Filter</title
1 min read
AngularJS Converting Functions
AngularJS Comparing Functions
AngularJS Questions
How to bundle an Angular app for production?Introduction Before deploying the web app, Angular provides a way to check the behavior of the web application with the help of a few CLI commands. Usually, the ng serves command is used to build, watch, and serve the application from local memory. But for deployment, the behavior of the application
4 min read
How to add many functions in one ng-click directive?The ng-click Directive in AngluarJS is used to apply custom behavior when an element is clicked. It can be used to show/hide some element or it can popup alert when the button is clicked. The ng-click directive is a very handy tool used in AngularJS. When an HTML is clicked, the ng-click directive t
2 min read
How to directly update a field by using ng-click in AngularJS ?In this article, we will see how to update the field directly with the help of the ng-click directive in AngularJS, along with understanding different ways to implement it through the implementations. Any field can be updated with ng-click using a custom JavaScript function. For this, we can make a
3 min read
How to Add Dynamic Options for Multiple Selects Inside ng-repeat Directive ?Given an HTML document containing some options element and the task is to add an array of javascript objects dynamically with multiple selects using ng-repeat in angularJS. Approach: The task is done using ng-repeat which loops through an array. Let's call this array "models". Each select menu prese
3 min read
How to detect when an @Input() value changes in Angular?@Input() is basically a decorator to bind a property as an input. It is used to pass data i.e property binding from one component to other or we can say, from parent to child component. It is bound with the DOM element. When the DOM element value is changed, Angular automatically updates this proper
3 min read
How to open popup using Angular and Bootstrap ?Adding Bootstrap to your Angular application is an easy process. Just write the following command in your Angular CLI. It will add bootstrap into your node_modules folder. ng add @ng-bootstrap/ng-bootstrap Approach: Import NgbModal module in the TypeScript file of the corresponding component, and th
2 min read
How to reload or re-render the entire page using AngularJS?While working with AngularJS we might come across a time when we want our user to switch contexts and re-render everything again.AngularJS provides a method by which we can re-render or even reload the entire page. So in this article, we will see how we can reload the route instead of just reloading
2 min read
How to add input fields dynamically on button click in AngularJS ?The task is to add an input field on the page when the user clicks on the button using AngularJs. Steps: The required component for the operation is created (add-inputComponent). In that component, html file (add-input.component.html) required html is written. In that HTML, the main div for input fi
2 min read
How to Create Button Dynamically with Click Event in Angular ?The task is to create a button dynamically with a click event using AngularJS, i.e., whenever someone clicks on the button then a new button gets created. The easiest way to create a button in AngularJS is to use the ng-repeat directive. We can easily hook up a repeat logic inside a button click eve
2 min read
How to use jQuery in Angular ?In this tutorial, we will learn how we can use jQuery with Angular. There are two ways in which we can use jQuery with Angular as discussed below: Table of Content By installing jQuery using the npm commandUsing jQuery CDN to use itBy installing jQuery using the npm commandYou can install the jQuery
2 min read
AngularJS Examples The following AngularJS section contains a wide collection of AngularJS examples. The AngularJS examples are categorized based on the topics including basics, directives, functions, and Miscellaneous. Each example section contains multiple approaches to solve the problems. Prerequisites: AngularJS T
2 min read