一种可行的解决方法是使用Angular的ChangeDetectorRef服务来手动更新绑定值,而不是依赖自动变更检测。在组件中注入ChangeDetectorRef服务,然后在mousedown和mouseup事件中调用detectChanges()方法。
示例代码如下:
import { Component, ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'app-component',
template:
})
export class AppComponent { value = 'Initial value';
constructor(private cd: ChangeDetectorRef) {}
onMouseDown() { this.value = 'New value'; }
onMouseUp() { this.cd.detectChanges(); } }