How to reuse template HTML block in Angular ? Last Updated : 25 Jul, 2024 Comments Improve Suggest changes Like Article Like Report Code Reusability is the capacity to repurpose pre-existing code when developing new software applications. It will allow you to store a piece of code that does a single task inside a defined block, and then call that code whenever you need it. In this article, we will learn How to reuse template HTML blocks in Angular.Steps for Installing & Configuring the Angular ApplicationStep 1: Create an Angular application using the following command.ng new appnameStep 2: After creating your project folder i.e. appname, move to it using the following command.cd appnameProject StructureIt will look like the following:Example 1: In this example, we will create a reuse a <h2> tag HTML <!-- app.component.html --> <ng-template #MsgRef> <h2 style="color: red">GeeksforGeeks</h2> <br> </ng-template> <h2 style="color: green;">GeeksforGeeks</h2> <h2>How to reuse template HTML block in Angular ?</h2> <ng-template [ngTemplateOutlet]="MsgRef"></ng-template> <ng-template [ngTemplateOutlet]="MsgRef"></ng-template> <ng-template [ngTemplateOutlet]="MsgRef"></ng-template> JavaScript // app.component.ts import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: "./app.component.html", styleUrls: ['./app.component.css'] }) export class AppComponent { } JavaScript // app.module.ts import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { HttpClientModule } from '@angular/common/http'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent, ], imports: [ BrowserModule, HttpClientModule, ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } Output:Example 2: In this example, we will reuse an image template. HTML <!-- app.component.html --> <ng-template #MsgRef> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20231009182919/Angular-PrimeNG-copy.webp"> <br> </ng-template> <h2 style="color: green;">GeeksforGeeks</h2> <h2>How to reuse template HTML block in Angular ?</h2> <ng-template [ngTemplateOutlet]="MsgRef"></ng-template> <ng-template [ngTemplateOutlet]="MsgRef"></ng-template> <ng-template [ngTemplateOutlet]="MsgRef"></ng-template> JavaScript // app.component.ts import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: "./app.component.html", styleUrls: ['./app.component.css'] }) export class AppComponent { } JavaScript // app.module.ts import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { HttpClientModule } from '@angular/common/http'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent, ], imports: [ BrowserModule, HttpClientModule, ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } Output: Comment More infoAdvertise with us Next Article How to reuse template HTML block in Angular ? A abhiisaxena09 Follow Improve Article Tags : Web Technologies AngularJS Geeks Premier League AngularJS-Questions Geeks Premier League 2023 +1 More Similar Reads Angular PrimeNG BlockUI Templates Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use Angular PrimeNG BlockUI Templates BlockUI component is used 3 min read How to Enable HTML 5 Mode in Angular 1.x ? HTML5 mode in Angular1.x is the configuration that replaces the default hash-based URLs and provides more user-friendly URLs using the HTML5 History API. This feature mainly enhances our one-page application and also provides a better experience to the users. We need to configure our server with pro 6 min read Introduction To Components And Templates in Angular Angular is a powerful framework for building dynamic, single-page web applications. One of the core concepts that make Angular so effective is its use of components and templates. Components and templates are the building blocks of any Angular application, allowing developers to create reusable, mai 6 min read AngularJS ng-bind-template Directive The ng-bind-template Directive in AngularJS is used to replace the content of an HTML element with the value of the given expression. It is used to bind more than one expression. It can have multiple {{ }} expressions. It is supported by all HTML elements. Syntax: The ng-bind-template Directive can 2 min read How to call an AngularJS Function inside HTML ? A Function is a set of statements that takes input, does some specific computation, and produces output. In this article, we will learn How to Call an AngularJS function inside HTML. To achieve this, we can use {{...}} to call the function from HTML. We can also pass arguments and return the result 3 min read Angular PrimeNG Form Editor Templates Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Angular PrimeNG Form Editor Templates. The Form Editor is a Qui 3 min read Angular PrimeNG Galleria Templates Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more. 4 min read How to Create a new module in Angular ? Modules are most important when it comes to building strong and scalable Angular applications. They help organize your code, promote modularity, and improve maintainability. It encourages collaboration among developers by grouping related components, directives, pipes, and services. In this article, 3 min read How to insert HTML into view from AngularJS controller? The ng-bind-html directive is a secure way of binding content to an HTML element. So in order to insert HTML into view, we use the respective directive. While using AngularJS, write HTML in our corresponding application, we should check the HTML for dangerous or error prone code. By including the "a 2 min read Like