Michelem Michelem - 1 year ago 75
Javascript Question

Angular JS and external libraries

I have a third party JavaScript library (not Angular) and I would like to use its methods/objects from Angular.

I know I can place a

<script type="text/javascript">
into an angular HTML view and use those methods there but that's really ugly.

How else could this be done?

Answer Source

Oh well, I found it, just attach to the $window and you are done.

As written here: https://developers.braintreepayments.com/javascript+node/sdk/client/setup

"The SDK will appear as braintree on the global window object."

So from your controller (for example) you can simply use $window.braintree and you got everything you need from Braintree client library.

To load the Dropin you can simply use this:

angular.module('app').controller('YourController', ['$scope', '$window',
    function ($scope, $window) {

        $window.braintree.setup('CLIENTTOKEN', 'dropin', {
            container: 'dropin'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download