【问题标题】:Angular 9 why the values ​in the view do not changeAngular 9 为什么视图中的值不会改变
【发布时间】:2020-08-25 13:07:42
【问题描述】:

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

这是为什么?

【问题讨论】:

  • 您好,为了其他人的帮助,您需要发布一些代码 sn-ps 进行审核。

标签: typescript view onchange angular9 webapi


【解决方案1】:

关于我的问题的代码 sn-p。

问题是视图没有用传感器数据更新..

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>

【讨论】:

    猜你喜欢
    • 2016-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-18
    相关资源
    最近更新 更多