角JS和外部库 [英] Angular JS and external libraries

查看:124
本文介绍了角JS和外部库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个第三方JavaScript库(不是角),我想使用它的方法/物体棱角分明。

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

我知道我可以放置一个<脚本类型=文/ JavaScript的方式> 成角HTML视图,并使用有这些方法,但是这是真的很丑

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.

如何还能这样做?

推荐答案

哦,我发现它,只需连接到$窗口和你做。

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

由于这里写的:<一href=\"https://developers.braintreepayments.com/javascript+node/sdk/client/setup\">https://developers.braintreepayments.com/javascript+node/sdk/client/setup

的SDK将显示为全局窗口对象布伦特里。

所以从你的控制器(例如),你可以简单地使用 $ window.braintree 和你有你布伦特里客户端库所需要的一切。

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

要加载可以简单地使用这个DROPIN:

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

    }
]);

这篇关于角JS和外部库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆