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 that I can place <script type="text/javascript"> in the angular HTML view and use these methods there, but it's really ugly.

How else can this be done?

+6
source share
2 answers

Ok, I found it, just join $window , and you're done.

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

"The SDK will be displayed as a dialog in the global window object. "

So, from your controller (for example) you can just use $window.braintree , and you have everything you need from the Braintree client library.

To download Dropin, you can simply use this:

 angular.module('app').controller('YourController', ['$scope', '$window', function ($scope, $window) { $window.braintree.setup('CLIENTTOKEN', 'dropin', { container: 'dropin' }); } ]); 
+7
source

Turn it on 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 Plunker or JSFiddle from a simple problem?

An example answer on how to use these two together: Encrypt credit card data using AngularJS in Braintree

+5
source

Source: https://habr.com/ru/post/978097/


All Articles