

Learn About Some Directives In Angular
source link: https://www.c-sharpcorner.com/article/learn-about-some-directives-in-angular/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introductions
- Attribute directives
- Structural directives
- Components directives
Attribute directives
- <style>
- .red{color: red}
- .green{color: green}
- </style>
- <p[ngClass]="{'red'=true, 'green'=false}">
- Angular attribute directive
- </p>
- import {Directive, ElementRef} from'@angular/core';
- @Directive({
- selector:'[my-directive]'
- exportclassMyDirective{
- constructor(elr:ElementRef){
- elr.nativeElement.style.background='yellow';
- import { NgModule } from'@angular/core';
- import { BrowserModule } from'@angular/platform-browser';
- import { MyDirective } from'./app.mydirective';
- import { AppComponent } from'./app.component';
- @NgModule({
- imports: [ BrowserModule ],
- declarations: [ AppComponent, MyDirective ],
- bootstrap: [ AppComponent ]
- exportclassAppModule { }
- import { Component, Input } from'@angular/core';
- @Component({
- selector:'app-root',
- templateUrl:'./app.component.html'
- exportclassAppComponent {
- name = 'Angular Directive ';
- <h3my-directive>Test Sat {{name}}</h3>
Structural directives
- import { Component, Input } from'@angular/core';
- @Component({
- selector:'app-root',
- templateUrl:'./app.component.html',
- exportclassAppComponent {
- name = 'Angular Directive ';
- numberlists=['1', '2', '3','4', '5', '6', '7'];
- <div*ngFor="let num of numberlists">
- <ng-container*ngIf = "(num == '1' || num == '3' || num == '5' || num == '7'); else elseTemplate">
- <h1>{{num}} is a odd number</h1>
- </ng-container>
- <ng-template#elseTemplate>
- <h1>{{num}} is even number</h1>
- </ng-template>
- </div>
Components directives
- @Component({
- selector:'app-root',
- templateUrl:'./app.component.html',
- styleUrls: ['./app.component.scss']
Recommend
-
40
A number of front-end libraries and even HTML 5 itself support the creation of custom HTML elements. A logical extension is custom attribute directives, but until now, only three libraries I am aware of make custom attri...
-
5
Structural Directives in Angular Structural directives are responsible for the HTML layout. They shape or reshape the HTML view by simply adding or removing the elements in the DOM. These directives are the way to handle ho...
-
7
Attribute directives in Angular What are Directives? Directives are elements which change the appearance or behavior of the DOM element. There are 3 types of the Directives mainly. We have categor...
-
6
Tutorial How To Use @HostBinding and @HostListener in Custom Angular Directives Angular Int...
-
7
Understanding Built In Angular Directives - Part 1 Today we will learn the built in directive...
-
5
Understanding Built In Angular Directives Today we will continue our journey to understand the remaining built in directives in Angular. This is a continuation of the previous
-
11
What are Directives in Angular?Directives are one of the most important concepts in Angular, In this section, we will see what is a directive and its types and how to create our own directives
-
12
-
5
Building Custom Structural and Attribute Directives in AngularAngular directives assist us in manipulating the DOM. We may customize a DOM element’s look, behavior, or layout using directives. In addition, they help...
-
7
Today, we will learn how to extend and customize Kendo UI components in our app using Angular directives. Directives help us with replicating configuration and behavior without adding extra components, and they have clear, scalable, semantic and t...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK