I know this isn't optimal, but I have regular javascript code changing a variable that is property in my component.
The reason for this is that I have dynamic javascript (that comes from Google Blockly) being run (eval
) in my component.
Here's the component template:
<input #textInput
[attr.max-value]="maxValue"
type="number"
style="width: 495px;"
(change)="onChange($event)"
[id]="key"
class="form-control"
[disabled]="disabled"
value="{{value}}" />
And the component code:
export class NumberStepComponent extends BaseStepComponent {
/** number-step ctor */
constructor() {
super();
}
@ViewChild("textInput") textInput: ElementRef;
private _maxValue: string;
get maxValue(): string {
return this._maxValue;
}
set maxValue(val: string) {
this._maxValue = val;
console.log("Changed ** : " + val);
}
}
When I change maxValue
from Angular, I do get the setter code triggered. But when jQuery does it, that setter isn't triggered.
ie:
var code = `$('#ID').attr('max-value', "5")`;
eval(code);
I've tried executing the code "in the zone" thinking this would keep Angular up to date:
this.ngZone.run(() => {
var code = `$('#ID').attr('max-value', "5")`;
eval(code);
});
Doesn't trigger the setter either. Any ways to achieve this ?
It's hard to guess what you can/cannot do but you can try to add a MutationObserver. For example :