如何从另一个JavaScript

时间:2019-07-02 08:17:16

标签: javascript angular

我正在尝试调用uploadFile('cde')方法来传递一些对象。

如何调用uploadFile('cde')。

index.html

<head>
<script>document.write('<script src="/assets/js/editor.js?v=' + Date.now() + '"><\/script>');</script>
</head>

<body>
 <script type="text/javascript">
        (function () {
            window['uploadFiles'] = function () {
                alert('hi');  <=== sucessfully getting alert
                uploadFile('cde');<=== call from here
            }
        })();
    </script>
</body>

editor.js

var nicUploadButton = nicEditorAdvancedButton.extend({
 uploadFile: function (obj) {
  alert('cde')  <=== this needs to be called
  }
})

1 个答案:

答案 0 :(得分:0)

在处理库时,您需要:

  1. npm install @yourLibrary --save dev
  2. 然后应将此库导入组件:

    import * as yourLib from 'yourLibrary';
    

,并在yourComponent中使用其方法:

yourLib.uploadFile('cde');