Component class

Declare reusable UI building blocks for an application.

Each Angular component requires a single @Component annotation. The @Component annotation specifies when a component is instantiated.

When a component is instantiated, Angular

  • creates a shadow DOM for the component,
  • loads the selected template into the shadow DOM and
  • creates all the injectable objects configured with providers and viewProviders.

All template expressions and statements are then evaluated against the component instance.

Lifecycle hooks

When the component class implements some lifecycle-hooks the callbacks are called by the change detection at defined points in time during the life of the component.

Inheritance
Annotations
  • @Target({TargetKind.classType})

Constructors

Component({required String selector, String? exportAs, List<Object> providers = const [], Visibility visibility = Visibility.local, List<Object> viewProviders = const [], List<Object?> exports = const [], int changeDetection = ChangeDetectionStrategy.Default, String? templateUrl, String? template, bool preserveWhitespace = false, List<String> styleUrls = const [], List<String> styles = const [], List<Object> directives = const [], List<Typed<Object>> directiveTypes = const [], List<Object> pipes = const [], ViewEncapsulation encapsulation = ViewEncapsulation.Emulated})
const

Properties

changeDetection int
Defines the used change detection strategy.
final
directives List<Object>
final
directiveTypes List<Typed<Object>>
Declares generic type arguments for any generic directives.
final
encapsulation ViewEncapsulation
final
exportAs String?
A name that can be used in the template to assign this directive to a variable.
finalinherited
exports List<Object?>
A list of identifiers that may be referenced in the template.
final
hashCode int
The hash code for this object.
no setterinherited
pipes List<Object>
final
preserveWhitespace bool
Removes all whitespace except &ngsp; and &nbsp; from template if set to false.
final
providers List<Object>
The set of injectable objects that are visible to the directive and its light DOM children.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selector String
The CSS selector that triggers the instantiation of the directive.
finalinherited
styles List<String>
final
styleUrls List<String>
final
template String?
final
templateUrl String?
final
viewProviders List<Object>
Defines the set of injectable objects that are visible to its view DOM children.
final
visibility Visibility
Whether this directive will be provided for injection.
finalinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited