简体   繁体   English

AngularJS无法与Paypal一起使用

[英]AngularJS doesn't working with paypal

I'm working in a project that I have to integrate angular with paypal plus. 我正在做一个项目,必须将angular与paypal plus集成在一起。 But when I put the script (paypal script) in a HTML the angular doesn't recognize the PAYPAL.apps.PPP script's variable I receives this error at console. 但是,当我将脚本( PAYPAL.apps.PPP宝脚本)放入HTML中时, PAYPAL.apps.PPP无法识别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 code: 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>

Someone here know how to integrate paypal with angular or imports others scripts to be used in application. 这里的某人知道如何将paypal与angular集成或导入其他脚本以在应用程序中使用。 o/ o /

It seems like the paypal js is not getting loaded or the angular script is running before it is loaded. 似乎Paypal js尚未加载,或者Angular脚本在加载之前正在运行。

I put the script in the html index.html :) 我将脚本放在html index.html中:)

您需要添加jQuery库。您应该在PAYPAL库之前添加它。

I'm working in a project with Angular 5 and I'd like to share my (almost) final solution to integrate Paypal Plus folowing the tipps from @Gleidson Ferreira. 我正在与Angular 5进行项目合作,我想分享(几乎)最终解决方案,以集成来自@Gleidson Ferreira的小费的Paypal Plus。

On the head of the index.html: 在index.html的头部:

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

On the checkout.component.ts: 在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'
    });
}

}

On checkout.component.html: 在checkout.component.html上:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM