I have this html code:
<textarea id="text-to-convert" on-change="change" value="{{text}}"></textarea>
And this dart code:
import "dart:html";
import 'package:polymer/polymer.dart';
@CustomTag('dictionary-converter')
class DictionaryConverter extends PolymerElement with ObservableMixin {
@observable String text = "Initial text";
void change(Event event, var detail, TextAreaElement textElement) {
print(textElement.value);
print(text);
}
}
In this case, the on-change
event is only triggered from time to time. (I haven't yet figured out when exactly).
When I remove the value={{text}}
binding, the event is properly fired every time the textare is changed.
Am I overlooking something or is this a bug?
Hi, this is because when we use [(ngModel)] where Input and Event binding are as one, every time you change the value of your input, it will also update at the same time but if we were to separate the Input and Event Binding, implementing [ngModel] and (ngModelChange), the angular doesn't know the new value being input ...
The onchange event occurs when the value of an element has been changed. For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed.
The change event triggers when the element has finished changing.
In the click event handler function, we are setting the value of select element to “marks” which is one of the options in the dropdown list and calling triggerChange() method by passing select element as parameter.
With Polymer 0.8+ you can use *yourFieldName**Changed. When the observed property changes, the Changed
method will be called. Since String text
is two way data bound, changing the value of the textarea will change the value of String text
and call the textChanged
method. This works with your original code and doesn't need ObservableBox
import "dart:html";
import 'package:polymer/polymer.dart';
@CustomTag('dictionary-converter')
class DictionaryConverter extends PolymerElement with ObservableMixin {
@observable String text = "Initial text";
textChanged(oldValue) {
print("textarea: ${this.shadowRoot.query("textarea").value}");
print("text: ${text}");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With