更改鼠标移动检测

时间:2017-07-13 20:23:42

标签: angular angular2-changedetection

在我的Angular应用程序中,我有一个 get 属性,它只是从服务中返回一个变量。 我在其中添加了一个增量变量,我注意到每次移动鼠标时都会调用它。 我认为这可能是一个重要的性能杀手。 我读到在http请求或按钮点击时触发了更改检测,但在我的情况下,它会在每次鼠标移动时触发。 在屏幕周围移动鼠标会在几秒钟内触发数千次变化检测。 在我的所有应用程序中,我从未处理鼠标移动事件。 即使在prodMode中,这种行为也会持续存在。

这是正常的吗?

这是我的代码片段:

Component.ts:

export class ImplantDataComponent implements OnInit {

    constructor(private configSvc: ConfigurationService) {}

    static i = 0;
    public get implantData(): ImplantData {
        console.log(ImplantDataComponent.i++);
        return this.configSvc.implantData;
    }
}

Component.html

<div class="col-md-4 form-group">
    <dx-number-box [(value)]="implantData.delay"></dx-number-box>
</div>

0 个答案:

没有答案