You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 16, 2022. It is now read-only.
import'dart:async';
import'dart:html';
import'package:angular/angular.dart';
import'package:angular_forms/angular_forms.dart';
@Directive(
selector:'[contenteditable][ngControl],''[contenteditable][ngFormControl],''[contenteditable][ngModel]',
)
classContentEditableDirectiveimplementsControlValueAccessor {
StreamSubscription removeDisabledState;
finalHtmlElement _element;
ContentEditableDirective(this._element) {
}
@HostListener('input')
voidhandleChange() {
onChange(_element.text, rawValue: _element.text);
}
/// Writes a new value to the element. /// This method will be called by the forms API to write /// to the view when programmatic (model -> view) changes are requested. /// See: [ControlValueAccessor](https://angular.io/api/forms/ControlValueAccessor#members)@overridevoidwriteValue(value) {
var normalizedValue = value ??'';
_element.text ='$normalizedValue';
}
/// This function is called by the forms API when the control status changes to or from "DISABLED". /// Depending on the value, it should enable or disable the appropriate DOM element.@overridevoidonDisabledChanged(bool isDisabled) {
if (isDisabled) {
_element.setAttribute('disabled', 'true');
removeDisabledState = _element.onKeyDown.listen((e) => e.preventDefault());
} else {
if (removeDisabledState !=null) {
_element.removeAttribute('disabled');
removeDisabledState.cancel();
}
}
}
TouchFunction onTouched = () {};
@HostListener('blur')
voidtouchHandler() {
onTouched();
}
/// Registers a callback function that should be called when the control receives a blur event. /// This is called by the forms API on initialization so it can update the form model on blur.@overridevoidregisterOnTouched(TouchFunction fn) {
onTouched = fn;
}
ChangeFunction<String> onChange = (String _, {String rawValue}) {};
/// Registers a callback function that should be called when /// the control's value changes in the UI. /// /// This is called by the forms API on initialization so it can update /// the form model when values propagate from the view (view -> model).@overridevoidregisterOnChange(ChangeFunction<String> fn) {
onChange = fn;
}
}
I am having this problem even though I created the "ContentEditableDirective" directive and implementing the "ControlValueAccessor"
As can be seen below
template
component
Directive