/** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import {ChangeDetectionStrategy} from '../change_detection/constants'; import {Provider} from '../di'; import {Type} from '../type'; import {TypeDecorator, makeDecorator, makePropDecorator} from '../util/decorators'; import {ViewEncapsulation} from './view'; /** * Type of the Directive decorator / constructor function. * * @stable */ export interface DirectiveDecorator { /** * @usageNotes * * ``` * import {Directive} from '@angular/core'; * * @Directive({ * selector: 'my-directive', * }) * export class MyDirective { * } * ``` * * @description * * Marks a class as an Angular directive and collects directive configuration * metadata. * * Directive decorator allows you to mark a class as an Angular directive and provide additional * metadata that determines how the directive should be processed, instantiated and used at * runtime. * * Directives allow you to attach behavior to elements in the DOM.. * * A directive must belong to an NgModule in order for it to be usable * by another directive, component, or application. To specify that a directive is a member of an * NgModule, * you should list it in the `declarations` field of that NgModule. * * In addition to the metadata configuration specified via the Directive decorator, * directives can control their runtime behavior by implementing various Life-Cycle hooks. * * **Metadata Properties:** * * * **exportAs** - name under which the component instance is exported in a template. Can be * given a single name or a comma-delimited list of names. * * **host** - map of class property to host element bindings for events, properties and * attributes * * **inputs** - list of class property names to data-bind as component inputs * * **outputs** - list of class property names that expose output events that others can * subscribe to * * **providers** - list of providers available to this component and its children * * **queries** - configure queries that can be injected into the component * * **selector** - css selector that identifies this component in a template * * @stable * @Annotation */ (obj: Directive): TypeDecorator; /** * See the {@link Directive} decorator. */ new (obj: Directive): Directive; } export interface Directive { /** * The CSS selector that triggers the instantiation of a directive. * * Angular only allows directives to trigger on CSS selectors that do not cross element * boundaries. * * `selector` may be declared as one of the following: * * - `element-name`: select by element name. * - `.class`: select by class name. * - `[attribute]`: select by attribute name. * - `[attribute=value]`: select by attribute name and value. * - `:not(sub_selector)`: select only if the element does not match the `sub_selector`. * - `selector1, selector2`: select if either `selector1` or `selector2` matches. * * * ### Example * * Suppose we have a directive with an `input[type=text]` selector. * * And the following HTML: * * ```html *