[英]AngularJS doesn't working with paypal
我正在做一個項目,必須將angular與paypal plus集成在一起。 但是,當我將腳本( 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代碼:
<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 /
似乎Paypal js尚未加載,或者Angular腳本在加載之前正在運行。
我將腳本放在html index.html中:)
您需要添加jQuery庫。您應該在PAYPAL庫之前添加它。
我正在與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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.