我需要根据 window.MediaRecorder 在 angular 6 中动态导入 javascript 文件

I need to dynamically import javascript file in angular 6 based on the window.MediaRecorder

1.can有人post实现这个的正确方法吗?

import { Component, OnInit } from '@angular/core';
if (!window['MediaRecorder']) {
 import * as MediaRecorder from 'audio-recorder-polyfill';
 } else {
declare var MediaRecorder: any;

}

使用 Es6 动态导入

The import keyword may be called as a function to dynamically import a module. When used this way, it returns a promise

import('/modules/my-module.js')
  .then((module) => {
    // Do something with the module.
  });

参考:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports

参考:https://netbasal.com/using-typescript-dynamic-imports-in-angular-d210547484dd