简体   繁体   中英

Call angular function from plain JS

I'm trying to integrate Fastsprings JS library into my Angular.js application. I have to embed Fastsprings library into my HTML head like:

<script id="fsc-api" src="..." data-popup-closed="onPopupClose" />

I've created a directive that uses document.createElement to build this script tag and add it to the document. My problem is that data-popup-closed contains the name of a callback function that is called if the fastspring popup gets closed. I tried to create this function inside my directive but that doesn't work because it only exists inside Angular scope then.

What is the best way to handle such situations? This is not a Fastspring specific question, this problem should always occur if you want to integrate a library which awaits a plain JS callback function.

Can you try to propagate "onPopupClose" function outside of the angulars scope? Do something like: window. onPopupClose = $scope. onPopupClose; in your angular app and then you can use this function outside.. just call window.onPopupClose()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM