@microsoft/fast-element > ElementController

ElementController class

Controls the lifecycle and rendering of a FASTElement.

Signature:

export declare class ElementController<TElement extends HTMLElement = HTMLElement> extends PropertyChangeNotifier implements HostController<TElement> 

Extends: PropertyChangeNotifier

Implements: HostController<TElement>

Remarks

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the ElementController class.

Properties

Property

Modifiers

Type

Description

behaviors

protected

Map<HostBehavior<TElement>, number> | null

The behaviors associated with the component.

context

readonly

ExecutionContext

The context the expression is evaluated against.

definition

readonly

FASTElementDefinition

The element definition that instructs this controller in how to handle rendering and other platform integrations.

hasExistingShadowRoot

protected

boolean

Indicates whether the element has an existing shadow root (e.g. from declarative shadow DOM).

isBound

readonly

boolean

Indicates whether the controller is bound.

isConnected

readonly

boolean

Indicates whether or not the custom element has been connected to the document.

mainStyles

ElementStyles | null

The main set of styles used for the component, independent of any dynamically added styles.

needsInitialization

protected

boolean

Indicates whether the controller needs to perform initial rendering.

shadowOptions

ShadowRootOptions | undefined

The shadow root options for the component.

source

readonly

TElement

The element being controlled by this controller.

sourceLifetime

readonly

SourceLifetime | undefined

Indicates how the source's lifetime relates to the controller's lifetime.

stage

protected

Stages

The current lifecycle stage of the controller.

template

ElementViewTemplate<TElement> | null

Gets/sets the template used to render the component.

view

readonly

ElementView<TElement> | null

The view associated with the custom element.

Methods

Method

Modifiers

Description

addBehavior(behavior)

Adds the behavior to the component.

addStyles(styles)

Adds styles to this element. Providing an HTMLStyleElement will attach the element instance to the shadowRoot.

bindObservables()

protected

Binds any observables that were set before upgrade.

connect()

Runs connected lifecycle behavior on the associated element.

connectBehaviors()

protected

Connects any existing behaviors on the associated element.

disconnect()

Runs disconnected lifecycle behavior on the associated element.

disconnectBehaviors()

protected

Disconnects any behaviors on the associated element.

emit(type, detail, options)

Emits a custom HTML event.

forCustomElement(element, override)

static

Locates or creates a controller for the specified element.

onAttributeChangedCallback(name, oldValue, newValue)

Runs the attribute changed callback for the associated element.

onUnbind(behavior)

Registers an unbind handler with the controller.

removeBehavior(behavior, force)

Removes the behavior from the component.

removeStyles(styles)

Removes styles from this element. Providing an HTMLStyleElement will detach the element instance from the shadowRoot.

renderTemplate(template)

protected

Renders the provided template to the element.

setStrategy(strategy)

static

Sets the strategy that ElementController.forCustomElement uses to construct ElementController instances for an element.