Dart Documentationangular.core.domNodeAttrs

NodeAttrs class

NodeAttrs is a facade for element attributes. The facade is responsible for normalizing attribute names as well as allowing access to the value of the directive.

class NodeAttrs {
 final dom.Element element;

 Map<String, List<AttributeChanged>> _observers;

 NodeAttrs(dom.Element this.element);

 operator [](String name) => element.attributes[_snakeCase(name, '-')];

 operator []=(String name, String value) {
   name = _snakeCase(name, '-');
   if (value == null) {
     element.attributes.remove(name);
   } else {
     element.attributes[name] = value;
   }
   if (_observers != null && _observers.containsKey(name)) {
     _observers[name].forEach((fn) => fn(value));
   }
 }

 /**
  * Observe changes to the attribute by invoking the [AttributeChanged]
  * function. On registration the [AttributeChanged] function gets invoked
  * synchronise with the current value.
  */
 observe(String attributeName, AttributeChanged notifyFn) {
   attributeName = _snakeCase(attributeName, '-');
   if (_observers == null) {
     _observers = new Map<String, List<AttributeChanged>>();
   }
   if (!_observers.containsKey(attributeName)) {
     _observers[attributeName] = new List<AttributeChanged>();
   }
   _observers[attributeName].add(notifyFn);
   notifyFn(this[attributeName]);
 }
}

Constructors

new NodeAttrs(Element element) #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
NodeAttrs(dom.Element this.element);

Properties

final Element element #

final dom.Element element

Operators

dynamic operator [](String name) #

operator [](String name) => element.attributes[_snakeCase(name, '-')];

dynamic operator []=(String name, String value) #

operator []=(String name, String value) {
 name = _snakeCase(name, '-');
 if (value == null) {
   element.attributes.remove(name);
 } else {
   element.attributes[name] = value;
 }
 if (_observers != null && _observers.containsKey(name)) {
   _observers[name].forEach((fn) => fn(value));
 }
}

Methods

dynamic observe(String attributeName, AttributeChanged notifyFn) #

Observe changes to the attribute by invoking the AttributeChanged function. On registration the AttributeChanged function gets invoked synchronise with the current value.

observe(String attributeName, AttributeChanged notifyFn) {
 attributeName = _snakeCase(attributeName, '-');
 if (_observers == null) {
   _observers = new Map<String, List<AttributeChanged>>();
 }
 if (!_observers.containsKey(attributeName)) {
   _observers[attributeName] = new List<AttributeChanged>();
 }
 _observers[attributeName].add(notifyFn);
 notifyFn(this[attributeName]);
}