AngularJS 不适用于贝宝

AngularJS doesn't working with paypal

我在一个项目中工作,我必须将 angular 与 paypal plus 集成。但是,当我将脚本(paypal 脚本)放入 HTML 时,angular 无法识别 PAYPAL.apps.PPP 脚本的变量,我在控制台收到此错误。

angular.js:13550 ReferenceError: PAYPAL is not defined
at eval (eval at globalEval (http://localhost:9000/bower_components/jquery/dist/jquery.js:343:5), <anonymous>:1:23)
at Function.globalEval (http://localhost:9000/bower_components/jquery/dist/jquery.js:343:5)
at domManip (http://localhost:9000/bower_components/jquery/dist/jquery.js:5291:15)
at jQuery.append (http://localhost:9000/bower_components/jquery/dist/jquery.js:5431:10)
at jQuery.<anonymous> (http://localhost:9000/bower_components/jquery/dist/jquery.js:5525:18)
at access (http://localhost:9000/bower_components/jquery/dist/jquery.js:3614:8)
at jQuery.html (http://localhost:9000/bower_components/jquery/dist/jquery.js:5492:10)
at link (http://localhost:9000/bower_components/angular/angular.js:25866:18)
at invokeLinkFn (http://localhost:9000/bower_components/angular/angular.js:9694:9)
at nodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:9093:11) <div ng-include="'app/account/payment/panel/paypal.html'" class="ng-scope">"

HTML代码:

<script src="https://www.paypalobjects.com/webstatic/ppplus/ppplus.min.js" type="text/javascript"></script>
<script type="application/javascript">
var ppp = PAYPAL.apps.PPP({"approvalUrl": '.$approvalUrl.',"placeholder": "ppplus","mode": "sandbox"});
</script>
<div id="ppplus"> </div>
<button type="submit"
id="continueButton"
onclick="ppp.doContinue(); return false;">Continuar
</button>

这里有人知道如何将 paypal 与 angular 集成或导入其他脚本以在应用程序中使用。 o/

您需要添加 jQuery library.You 应该在 PAYPAL 库之前包含它。

似乎没有加载 paypal js 或 angular 脚本在加载之前 运行。

我把脚本放在html index.html :)

我正在与 Angular 5 合作,我想分享我的(几乎)最终解决方案,以根据@Gleidson Ferreira 的提示整合 Paypal Plus。

在index.html的头上:

<script src="https://www.paypalobjects.com/webstatic/ppplus/ppplus.min.js" type="text/javascript"></script>

在 checkout.component.ts:

import { Component, OnInit } from '@angular/core';
declare var PAYPAL: any;

@Component({
    selector: 'checkout',
    templateUrl: './checkout.component.html'
})
export class CheckoutComponent implements OnInit {
    paypalPlus: any;

    ngOnInit() {

    // TODO: add further customization to get your own proval URL dinamically
    this.paypalPlus = PAYPAL.apps.PPP(
    {
     'approvalUrl': 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-31737613MN931841V',
      'placeholder': 'ppplus',
       'mode': 'sandbox'
    });
}

}

在 checkout.component.html 上:

<div class="row" id="ppplus"> </div>