“导航器”类型上不存在属性蓝牙

2023-12-24

我综合了示例代码 https://googlechrome.github.io/samples/web-bluetooth/device-information-characteristics.html进入我的 Angular 6 项目。但有一些编译错误。这些错误之一是: “导航器”类型上不存在属性“蓝牙”。

为什么会发生这个错误以及如何解决它?


我不确定为什么会发生此错误,但您可以通过安装类型来修复它,npm install --save-dev @types/web-bluetooth,并使用三斜杠指令,/// <reference types="web-bluetooth" />,像这样:

/// <reference types="web-bluetooth" />

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  title = 'myApp';

  async test() {
    try {
      const device = await navigator.bluetooth.requestDevice({
        filters: [
          {
            namePrefix: 'test',
          },
        ],
        optionalServices: ['test'],
      });
    } catch (error) {
      console.error(error);
    }
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“导航器”类型上不存在属性蓝牙 的相关文章

随机推荐