Javascript 如何在form.valuechanges.subscribe()中获取输入事件的HtmleElement?
我正在重写我的代码,因为在使用IPAD时,这个代码不起作用。 所以我想我应该使用这个.form.valuechanges()而不是change事件 但是我被卡住了,因为我不知道如何在valuechanges.subscribe()中操作DOM 当文本区域中的值发生更改时,td背景颜色也会更改为不同的颜色 所以我想在这个.form.valuechanges.subscribe()中做同样的事情 我可以在表中获取事件对象。但是我无法在这个.form.valuechanges.subscribe((val)=>{})中获取事件对象 案例1:使用变更事件(这就是我想要做的) HTML 案例2:使用valuechanges方法(我认为这是更好的方法)Javascript 如何在form.valuechanges.subscribe()中获取输入事件的HtmleElement?,javascript,angular,reactive-forms,Javascript,Angular,Reactive Forms,我正在重写我的代码,因为在使用IPAD时,这个代码不起作用。 所以我想我应该使用这个.form.valuechanges()而不是change事件 但是我被卡住了,因为我不知道如何在valuechanges.subscribe()中操作DOM 当文本区域中的值发生更改时,td背景颜色也会更改为不同的颜色 所以我想在这个.form.valuechanges.subscribe()中做同样的事情 我可以在表中获取事件对象。但是我无法在这个.form.valuechanges.subscribe((v
表单属性是FormGroup/FormControl吗?如果不是,为了得到反应形式,你应该考虑这一点——>我的表单是Frand组。Top FormGroup具有FormGroup的FormArray。您的表单属性是FormGroup/FormControl吗?如果不是,为了得到反应形式,你应该考虑这一点——>我的表单是Frand组。顶级FormGroup拥有FormGroup的FormArray。
<td mat-cell *matCellDef="let element; let index = index" class="column-order">
<mat-form-field class="not-fix-width text-right" [formGroupName]="index">
<input
matInput
type="text"
(change)="valueChanged(element, $event, $event.target.value)"
formControlName="order"
/>
</mat-form-field>
</td>
constructor(
private platform: Platform,
private cd: ChangeDetectorRef,
private renderer: Renderer2) {}
valueChanged(parameter: any, event: any, order: string) {
const copy = this.dataSource.data().slice();
order = this.checkValue(order);
parameter.order = order;
this.dataUpdate(copy);
// compare before value and after value
if (this.isSameOldValue(parameter['name'], order)) {
this.renderer.removeClass(this.getHtmlElement(event.srcElement.parentElement), 'coloredBackground');
} else {
this.renderer.addClass(this.getHtmlElement(event.srcElement.parentElement), 'coloredBackground');
}
}
getHtmlElement(elem: HTMLElement) {
if (elem.parentElement.nodeName === 'TD') {
return elem.parentElement;
} else {
return this.getHtmlElement(elem.parentElement);
}
}
dataUpdate(copy: Param[]) {
this.dataSource.update(copy);
this.edited.emit({
parameters: this.dataSource.data().slice(),
code: this.value.code,
index: this.index,
invalid: this.form.invalid,
});
}
ngOnInit() {
this.initForm();
this.form.valueChanges
.pipe(distinctUntilChanged())
.pipe(takeUntil(this.onDestroy$))
.subscribe((nowValue) => {
// compare before value and after value
// make flag for visible/invisible save button
// this.changeDetectorRef.detectChanges()
});
}