It's all about Technology. Angular with Core .Net and MVC Razor Engine
How to create @Directives in Angular
Get link
Facebook
Twitter
Pinterest
Email
Other Apps
Angular - How to create @Directives in Angular , ANGULAR WITH CORE .NET AND MVC RAZOR ENGINE
Directives in Angular
What is Directive?
The directive is markers on a DOM element that tell Angular to attach a specified behavior to that DOM element or even transform the DOM element and its children.
Types of Directive
There are 4 type of Directives listed below
Components directives : It is mainly used to specify the HTML templates. It is the most commonly-used directive in an Angular project. It is decorated with the @component decorator e.g. app.component
Structural directives : The structural directive is used to add or remove the HTML Element in the Dom Layout e.g. *ngIf , *ngFor .. etc
Attribute directives : The Attribute directives is used to change/modify apearance of DOM element *ngClass , *ngStyle .. etc
Custom Directive : The Custom Directive is created by a developer based on requirement
Advantage of using Custom Directive
it is vulnerable to XSS attacks when we directly use ElementRef in our application. It is better to create a custom directive and use ElementRef inside directive to change appearance or behavior of the host element.
HostListener & HostBinding
HostListener : This is a function decorator that accepts an event name as an argument. When that event gets fired on the host element it calls the associated function.
HostBinding : This is a function decorator that accepts a css style as an argument.
Let's create one custom directive based on our requirement to understand it better
Requirement : Create a directive which will increase and decrease font size of DOM element on mouse enter and hover and will also change its background color
Let's follow below step to full fill the requirement
Step 1: Create a new Projet using command ng new Directive-Angular
Step 2: Create a custom direct using command ng g directive TextTransformation
How to disable table row in Angular ? , ANGULAR WITH CORE .NET AND MVC RAZOR ENGINE How to disable table row in Angular In this article we will learn how to disable every alternate (even) row in Table by using CSS. Step 1: Let's create an HTML table using below code <table class="main-table"> <thead> <tr> <th> Sr No. </th> <th> Fruit Name </th> </tr> </thead> <tbody> <tr *ngFor="let fruit of duplicateArray; let i = index; let even = even">
How to disable table row in Angular ? , ANGULAR WITH CORE .NET AND MVC RAZOR ENGINE How to create XML file dynamically in c#.net? In this article we will learn , How to create dynamic file in c#.net using ASP.NET CORE C# Step 1: Let's create a solution to implement How to create XML file dynamically in c#.net? File -> New -> Project -> ASP.NET Core Web Application -> Next -> Enter file name and click create Step 2: Create a new action method in Home controller and create a view and add below html code in view @{ ViewData["Title"] = "Generate XML File"; } @ViewData["Title"] We will use this page to generate XML file. Step 3: Create a new action like below and have a look on below Code [HttpPost] public IActionResult GenerateXMLFile(string action) { if (!string.IsNullOrEmpty(action)) { string xmlData = generateFile(); string xmlString = xmlData; string f
How to get Array value in Angular ? , ANGULAR WITH CORE .NET AND MVC RAZOR ENGINE How to get Array value in Angular? In this article we will learn , How to get array value in Angular . Step 1 : Create a new Angular Project using below command ng new angular-tour-of-heroes Step 2 : Create a new component using below command ng generate component how-to-get-array-value-in-angular Step 3 : Add Below code in how-to-get-array-value-in-angular.component.ts import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-how-to-get-array-angular', templateUrl: './how-to-get-array-angular.component.html', styleUrls: ['./how-to-get-array-angular.component.scss'] }) export class HOWTOGETArrayAngularComponent implements OnInit { fruits = ['Apple', 'Orange', 'Banana', 'blackberry', 'blackcurrant', 'blueberry', 'cherry' , 'coconut'
Comments
Post a Comment