Component decorator and metadata.
Animations are defined on components via an animation-like DSL. This DSL approach to describing animations allows for a flexibility that both benefits developers and the framework.
Animations work by listening on state changes that occur on an element within the template. When a state change occurs, Angular can then take advantage and animate the arc in between. This works similar to how CSS transitions work, however, by having a programmatic DSL, animations are not limited to environments that are DOM-specific. (Angular can also perform optimizations behind the scenes to make animations more performant.)
For animations to be available for use, animation state changes are placed within
{@link trigger animation triggers} which are housed inside of the animations
annotation
metadata. Within a trigger both {@link state state} and {@link transition transition} entries
can be placed.
```typescript
Defines the used change detection strategy.
When a component is instantiated, Angular creates a change detector, which is responsible for propagating the component's bindings.
The changeDetection
property defines, whether the change detection will be checked every time
or only when the component tells it to do so.
Specifies how the template and the styles should be encapsulated:
ViewEncapsulation.Native
} to use shadow roots - only works
if natively available on the platform,ViewEncapsulation.Emulated
} to use shimmed CSS that
emulates the native behavior,ViewEncapsulation.None
} to use global CSS without any
encapsulation.When no encapsulation
is defined for the component, the default value from the
{@link CompilerOptions} is used. The default is ViewEncapsulation.Emulated
}. Provide a new
CompilerOptions
to override this value.
If the encapsulation is set to ViewEncapsulation.Emulated
and the component has no styles
nor styleUrls
the encapsulation will automatically be switched to ViewEncapsulation.None
.
Defines the components that should be compiled as well when this component is defined. For each components listed here, Angular will create a {@link ComponentFactory} and store it in the {@link ComponentFactoryResolver}.
Defines the name that can be used in the template to assign this directive to a variable.
```
Specify the events, actions, properties and attributes related to the host element.
Specifies which DOM events a directive listens to via a set of (event)
to method
key-value pairs:
event
: the DOM event that the directive listens to.statement
: the statement to execute when the event occurs.
If the evaluation of the statement returns false
, then preventDefault
is applied on the DOM
event.To listen to global events, a target must be added to the event name.
The target can be window
, document
or body
.
When writing a directive event binding, you can also refer to the $event local variable.
The following example declares a directive that attaches a click listener to the button and counts clicks.
```typescript
Enumerates the set of data-bound input properties for a directive
Angular automatically updates input properties during change detection.
The inputs
property defines a set of directiveProperty
to bindingProperty
configuration:
directiveProperty
specifies the component property where the value is written.bindingProperty
specifies the DOM property where the value is read from.When bindingProperty
is not provided, it is assumed to be equal to directiveProperty
.
The following example creates a component with two data-bound properties.
```typescript
Overrides the default encapsulation start and end delimiters (respectively )
The module id of the module that contains the component.
Needed to be able to resolve relative urls for templates and styles.
In CommonJS, this can always be set to module.id
, similarly SystemJS exposes __moduleName
variable within each module.
```
Enumerates the set of event-bound output properties.
When an output property emits an event, an event handler attached to that event the template is invoked.
The outputs
property defines a set of directiveProperty
to bindingProperty
configuration:
directiveProperty
specifies the component property that emits events.bindingProperty
specifies the DOM property the event handler is attached to.```typescript
If {@link Component#preserveWhitespaces Component.preserveWhitespaces} is set to false
potentially superfluous whitespace characters (ones matching the \s
character class in
JavaScript regular expressions) will be removed from a compiled template. This can greatly
reduce AOT-generated code size as well as speed up view creation.
Current implementation works according to the following rules:
<button>Action 1</button> <button>Action 2</button>
will be converted to
<button>Action 1</button><button>Action 2</button>
(no whitespaces between buttons);<span>\n some text\n</span>
will be converted to <span> some text </span>
);<pre>
,
<textarea>
).Described transformations can (potentially) influence DOM nodes layout so the
preserveWhitespaces
option is true
be default (no whitespace removal).
In Angular 5 you need to opt-in for whitespace removal (but we might revisit the default
setting in Angular 6 or later). If you want to change the default setting for all components
in your application you can use the preserveWhitespaces
option of the AOT compiler.
Even if you decide to opt-in for whitespace removal there are ways of preserving whitespaces
in certain fragments of a template. You can either exclude entire DOM sub-tree by using the
ngPreserveWhitespaces
attribute, ex.:
<div ngPreserveWhitespaces>
whitespaces are preserved here
<span> and here </span>
</div>
Alternatively you can force a space to be preserved in a text node by using the &ngsp;
pseudo-entity. &ngsp;
will be replaced with a space character by Angular's template
compiler, ex.:
<a>Spaces</a>&ngsp;<a>between</a>&ngsp;<a>links.</a>
will be compiled to the equivalent of:
<a>Spaces</a> <a>between</a> <a>links.</a>
Please note that sequences of &ngsp;
are still collapsed to just one space character when
the preserveWhitespaces
option is set to false
. Ex.:
<a>before</a>&ngsp;&ngsp;&ngsp;<a>after</a>
would be equivalent to:
<a>before</a> <a>after</a>
The &ngsp;
pseudo-entity is useful for forcing presence of
one space (a text node having &ngsp;
pseudo-entities will never be removed), but it is not
meant to mark sequences of whitespace characters. The previously described
ngPreserveWhitespaces
attribute is more useful for preserving sequences of whitespace
characters.
Defines the set of injectable objects that are visible to a Directive and its light DOM children.
Here is an example of a class that can be injected:
``` class Greeter { greet(name:string) { return 'Hello ' + name + '!'; } }
Configures the queries that will be injected into the directive.
Content queries are set before the ngAfterContentInit
callback is called.
View queries are set before the ngAfterViewInit
callback is called.
```
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.Suppose we have a directive with an input[type=text]
selector.
And the following HTML:
<form>
<input type="text">
<input type="radio">
<form>
The directive would only be instantiated on the <input type="text">
element.
Specifies stylesheet URLs for an Angular component.
Specifies inline stylesheets for an Angular component.
Specifies an inline template for an Angular component.
Only one of templateUrl
or template
can be defined per Component.
Specifies a template URL for an Angular component.
Only one of templateUrl
or template
can be defined per View.
Defines the set of injectable objects that are visible to its view DOM children.
Here is an example of a class that can be injected:
``` class Greeter { greet(name:string) { return 'Hello ' + name + '!'; } }
This callback is called when the a routed component's state is about to be exited.
This callback is called when the a routed component's state is about to be exited.
The callback can be used to cancel or alter the new Transition that would otherwise exit the component's state.
This callback is used to inform a view that it is about to be exited, due to a new Transition. The callback can ask for user confirmation, and cancel or alter the new Transition. The callback should return a value, or a promise for a value. If a promise is returned, the new Transition waits until the promise settles.
Called when:
ui-view
Called with:
Transition
that is about to exit the component's state```js
a hook result which may cancel or alter the pending Transition (see HookResult)
Generated using TypeDoc
The shape of a controller for a view (and/or component), defining the controller callbacks.
A UI-Router view has an Angular
Component
(see Ng2ViewDeclaration.component). TheComponent
may define component-level hooks which UI-Router will call at the appropriate times. These callbacks are similar to Transition Hooks (IHookRegistry), but are only called if the view/component is currently active.This interface defines the UI-Router component callbacks.