Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 886
michelem Avatar asked Nov 12 '14 16:11

michelem


2 Answers

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'
        });

    }
]);
like image 83
michelem Avatar answered Oct 20 '22 01:10

michelem


Include it before Angular and you should be fine

<script type="text/javascript" src="braintree.js">
<script type="text/javascript" src="angular.js">

Using it with angular should not be a problem.

Can you create a Plunker or JSFiddle of a simple problem?

Sample answer of how to use the two together: Encrypting credit card details using AngularJS in Braintree

like image 27
SoluableNonagon Avatar answered Oct 20 '22 00:10

SoluableNonagon