@Directive
This is the documentation for Angular 7.
You can switch to the latest version Angular 10.
You can switch to the latest version Angular 10.
Marks a class as an Angular directive. You can define your own directives to attach custom behavior to elements in the DOM. The options provide configuration metadata that determines how the directive should be processed, instantiated and used at runtime.
Example
To define a directive, mark the class with the decorator and provide metadata.
import {Directive} from '@angular/core';
@Directive({
selector: 'my-directive',
})
export class MyDirective {
...
}
Declaring directives
Directives are declarables.
They must be declared by an NgModule
in order to be usable in an app. A directive must belong to exactly one NgModule
.
declarations: [
AppComponent,
MyDirective
],
Options
exportAs
#
exportAs?: string
host
#
host?: {[key: string]: string}
inputs
#
inputs?: string[]
jit
#
jit?: true
outputs
#
outputs?: string[]
providers
#
providers?: Provider[]
queries
#
queries?: {[key: string]: any}
selector
#
selector?: string