我必须在Angular 7项目中包括一个名为RappidJS的库和许多Jquery文件。 我在组件中使用了自制功能:
ngOnInit() {
this.loadScript('./app/assets/node_modules/jquery/dist/jquery.js');
this.loadScript('./app/assets/node_modules/lodash/index.js');
this.loadScript('./app/assets/node_modules/backbone/backbone.js');
this.loadScript('./app/assets/build/rappid.min.js');
this.loadScript('./app/assets/src/joint.ui.inspector.min.js');
this.loadScript('./app/assets/src/joint.shapes.qad.js');
this.loadScript('./app/assets/src/selection.js');
this.loadScript('./app/assets/src/factory.js');
this.loadScript('./app/assets/src/snippet.js');
this.loadScript('./app/assets/src/app.js');
this.loadScript('./app/assets/src/index.js');
}
public loadScript(url: string) {
const body = <HTMLDivElement>document.body;
const script = document.createElement('script');
script.innerHTML = '';
script.src = url;
script.async = false;
script.defer = true;
body.appendChild(script);
}
JS执行正常,我的应用程序显示出来没有任何问题。但是,我需要与“ app.js”中的某些函数进行通信,以获取一些json并将其用于我的角度应用程序。
在我的component.html中,我有一个工具栏:
<div id="toolbar">
<button class="btn btn-secondary add-question">Ajouter Question</button>
<button class="btn btn-secondary add-answer">Ajouter Réponse</button>
<button class="btn btn-secondary add-API">Ajouter module API</button>
<button class="btn btn-success add-APIEX">Ajouter module Ping</button>
<button class="btn send-json">Envoyer JSON</button>
<button class="btn btn-secondary preview-dialog">Lancer dialogue</button>
<button class="btn btn-secondary code-snippet">Code Snippet</button>
<button class="btn btn-secondary clear">Effacer Tableau</button>
<button class="btn btn-secondary load-example">Charger le JSON</button>
</div>
and in app.js i have this :
events: {
'click #toolbar .add-question': 'addQuestion',
'click #toolbar .add-API': 'addAPI',
'click #toolbar .add-APIEX': 'addAPIEX',
'click #toolbar .add-answer': 'addAnswer',
'click #toolbar .send-json': 'sendJson',
'click #toolbar .preview-dialog': 'previewDialog',
'click #toolbar .code-snippet': 'showCodeSnippet',
'click #toolbar .load-example': 'loadExample',
'click #toolbar .clear': 'clear'
},
sendJson:function(){}
我真的很想知道这些之间是否有一种交流方式?
谢谢