contents property

  1. @Input.new()
set contents (String value)
inherited

HTML to display in the component.

Implementation

@Input()
set contents(String value) => _domService.scheduleWrite(() {
      // Cache the target element, if we haven't done so already.
      _cachedTargetElement ??= targetElement;

      // If there are existing listeners, dispose of them now.
      _subscriptionDisposer.dispose();

      // If there is no target element, there is nothing else to do.
      if (_cachedTargetElement == null) return;

      // Update the DOM.
      try {
        _cachedTargetElement!.setInnerHtml(value, validator: _nodeValidator);
      } catch (e) {
        if (e is _UnsafeUriError) {
          _logger.shout('simple-html used untrusted URI: $e', e);
        } else if (e is _MalformedElementError) {
          _logger.shout('simple-html used malformed element: $e', e);
        } else {
          rethrow;
        }
      }

      // Register new click listeners if necessary. Do this through a
      // scheduled read to ensure the above setInnerHtml has fully resolved
      // before probing the DOM again.
      _domService.scheduleRead(() {
        // Instruct each trigger element to send its events to
        // _triggerStreamController and register that subscription for later
        // clean-up (e.g. when this component is destroyed).
        _cachedTargetElement!
            .querySelectorAll(_triggerSelector)
            .map((link) => link.onClick.listen(_triggerStreamController.add))
            .forEach(_subscriptionDisposer.addStreamSubscription);
      });
    });