BackgroundBehavior AttributeBehavior

Attribute behaviors are part of Mahalo's special template syntax.They can be used to change a DOM elements attribute when an expression'sresult changes.

To make use of them you can prefix the attribute you want to set witha # symbol.

Example

This simple example sets the id of a div element to the value of myPropertywhich is looked up in the local scope.

<div #id="myProperty"></div>
alias

{ default } from mahalo/behaviors/attribute-behavior

Hierarchy

Index

Constructors

Properties

Methods

Object literals

Constructors

constructor

Properties

element

element:Element

The element the behavior was attached to.

name

name:string

The name of the attribute that will be changed.

Static bindings

bindings:Object

This static property lets you define listeners that will be executed whenproperties of the behavior change.

It should be a map where the keys are paths that should be watched on the behavior instanceand the values are names of methods that will be invoked on it when the valueat a path changes.

Example

The following example shows a behavior that reacts to a change in the height ofthe defining element.

export default class MyBehavior extends Behavior {    static inject: {element: Element};    static bindings = {        'element.clientHeight': 'heightChange'    };    width: number;    heightChange(height: number) {        this.width = height * 2;    }}

Static update

update:string = "update"

Methods

remove

  • remove(): void
  • Returns void

update

  • update(newValue: any): void
  • Updates the attribute when the result of the expressionhas changed.

    Parameters
    • newValue: any
    Returns void

Object literals

Static inject

inject:object

element

element:Element = Element