Paypal登录AngularJS中的按钮集成

时间:2016-01-12 14:51:11

标签: javascript angularjs paypal

我从here生成了LoginPaypal按钮的代码片段,它产生了这样的内容:

<span id="paypalButton"></span>
<script src="https://www.paypalobjects.com/js/external/api.js"></script>
<script>
    paypal.use( ["login"], function(login) {
      login.render ({
        "appid": <appid>,
        "authend": "sandbox",
        "scopes": "profile email address phone https://uri.paypal.com/services/paypalattributes",
        "containerid": "paypalButton",
        "locale": "en-us",
        "returnurl": "http://my.domain.here/return.php"
      });
    });
</script>

我的应用是一个AngularJS应用,并且整合了这个代码片段会在浏览器控制台中抛出此错误:

ReferenceError: paypal is not defined
at eval (eval at <anonymous> (http://localhost:8080/meritwork/assets/javascript/library/jquery.js:330:5), <anonymous>:1:1)
at eval (native)
at Function.jQuery.extend.globalEval (http://localhost:8080/meritwork/assets/javascript/library/jquery.js:330:5)
at jQuery.fn.extend.domManip (http://localhost:8080/meritwork/assets/javascript/library/jquery.js:5411:16)
at jQuery.fn.extend.append (http://localhost:8080/meritwork/assets/javascript/library/jquery.js:5194:15)
at null.<anonymous> (http://localhost:8080/meritwork/assets/javascript/library/jquery.js:5309:18)
at jQuery.access (http://localhost:8080/meritwork/assets/javascript/library/jquery.js:3465:8)
at jQuery.fn.extend.html (http://localhost:8080/meritwork/assets/javascript/library/jquery.js:5276:10)
at removePatch [as html] (http://localhost:8080/meritwork/assets/javascript/library/angular.js:2292:25)
at link (http://localhost:8080/meritwork/assets/javascript/library/angular-route.min.js:7:180) <div ng-view="" style="padding-top: 70px" class="ng-scope">

我是这个领域的新手,我不太明白这个错误。我试着查找它并没有找到任何东西。有没有人对它可能出错的地方有任何建议?

谢谢。

1 个答案:

答案 0 :(得分:0)

解决。问题是paypal所需的js需要jquery,而jquery是在paypal js之后加载的。在jquery之后移动了脚本包含,一切顺利。