角度9,为什么视图中的值不改变

问题描述 投票:1回答:1

我经常使用WebSensorApi,并希望在我的视图中显示传感器值。在过去的项目中,显示的值没有任何问题。现在,我在另一个项目中使用了完全相同的代码,并且仅当触发click事件时,视图才会发生奇怪的变化。与它完全无关。

为什么?

typescript view onchange angular9 webapi
1个回答
0
投票

有关我的问题的代码段。

问题是视图未使用传感器数据进行更新..

component.ts

.
.
.
count;
permission: Boolean = true;

ngOnInit() {
    this.getAcceleration();
  }



getAcceleration() {
    if (this.isPermission) {
     (DeviceMotionEvent as any).requestPermission()
      .then(permissionState => {
      if (permissionState === 'granted') {
       window.addEventListener('devicemotion', (data) => {
        this.count = data.acceleration.x;
       });
      }
     })
      .catch(console.error);
    } else {

    }
   }

.
.
.

component.html

<h1>Show Acceleration data</h1>

<p>{{count}}</p>
© www.soinside.com 2019 - 2024. All rights reserved.