ng build error - 属性'requestMIDIAc​​cess'不存在

时间:2016-11-15 13:17:17

标签: angular

我正在尝试使用Web Midi API构建Angular2项目。

运行from flask import Flask, Response, request app = Flask(__name__) @app.route('/', methods=['POST']) def get_data(): print('Recieved from client: {}'.format(request.data)) return Response('We recieved something…') if __name__ == '__main__': app.run(debug=True) 时,由于抛出某些错误,我无法完成此过程,具体来说:

Error in bail mode: [default] /Users/JmsToh/GitHub/web-editor/web-editor/src/app/midi.service.ts:43:22 
Property 'requestMIDIAccess' does not exist on type 'Navigator'.

这来自代码的这一部分:

ng build

运行if (navigator.requestMIDIAccess) { this.browserMidiCompatible = true; navigator.requestMIDIAccess({ sysex: false }) .then(this.onMIDISuccess.bind(this), this.onMIDIReject.bind(this)); } else { alert("Platform not compatible"); } 时,该应用在Chrome上正常运行。有没有办法让Angular2在构建时忽略错误?

4 个答案:

答案 0 :(得分:3)

好的,我设法通过这样做来删除此错误:

navigator["requestMIDIAccess"]

答案 1 :(得分:3)

使用以下方法添加necessary type definitions

npm install @types/webmidi

重新启动tsc后应自动发现它们。

  

注意:如果在安装库之后看到错误“找不到名称Map”,请参阅this answer

答案 2 :(得分:1)

安装@types/webmidi使我可以使用定义并使vs代码正常工作,但是不足以进行编译。

我能够通过在tsconfig中添加此编译器选项来解决此问题: "types": ["webmidi"]

答案 3 :(得分:0)

通过npm install -s @types/webmidi命令安装,Angular 7可以在源代码中使用它:

const requestMIDIAccess = navigator['requestMIDIAccess'];
if (requestMIDIAccess) {
  requestMIDIAccess().then(onMIDISuccess, onMIDIFailure);
  console.log('This browser supports WebMIDI!');
} else {
  console.log('WebMIDI is not supported in this browser.');
}
相关问题