2017-02-13 76 views
1

我想動態創建一個使用包含我的角度2組件呈現的數據對象的價格的PayPal結帳按鈕。我想通過貝寶快遞代碼一個金額,並讓我打開我的結帳組件,但我有巨大的問題,爲我提供了一個按鈕。PayPal快速結算角度2組件 - 加載問題?

我遵循這個指南:https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/basic-integration/但如果我嘗試包括paypals組件中的腳本代碼它不會加載,如果我把代碼在我的index.html腳本加載,並給了我這個錯誤:

ppxo_xc_ppbutton_error Object {error:「Error:Document is ready and element#paypal-butto ... calhost:3000/vendor.bundle.js:139776:25)[]」,timestamp:1486999989713,windowID:「be296e274d」,pageID:「a63dc0f8ab 」主機: 「本地主機:3000」 ...}

錯誤:文獻是準備和元素#貝寶按鈕不會在https://www.paypalobjects.com/api/checkout.js:5176:39 [] 存在 在Zone.runTask(http://localhost:3000/vendor.bundle.js:138551:47)[=>] 在ZoneTask.invoke(http://localhost:3000/vendor.bundle.js:138745:33)[] 在data.args(匿名功能)(http://localhost:3000/vendor.bundle.js:139776:25)[]

  • unhandled_error對象{消息:「錯誤:文檔準備好和元件#paypal-button does not exist「,stack:」Error:Document is ready and element#paypal-butto ... calhost:3000/vendor.bundle.js:139776:25)[]「,errtype:」[object Object]「 ,事件:「ppxo_unhandled_error」,版本:「4.0.39」...} zone.js:155未捕獲ZoneAwareError {__zone_symbol__error:錯誤:文檔已準備好,元素#paypal-button不存在 在https://www.paypalobjects。,__zone_symbol__stack:「錯誤:文檔已準備就緒,元素#paypa 1-butto ... calhost:3000/vendor.bundle.js:139776:25)[]「}
+0

你有使用'ID = 「貝寶按鈕」'元素?當你調用'paypal.Button.render()'時,該元素是否存在? – bluepnume

+0

my id =「paypal-button元素在角度組件中呈現的時間比我在插入貝寶腳本後的時間要長,這會導致上面發佈的錯誤,只有當腳本放置在index.html中時纔會加載腳本。最後使用後端SDK並在我的快速服務器上實現它。感謝雖然 – seanEd

回答

2

您需要添加下面的代碼在你的角度成分 聲明讓貝寶:所有;

然後你可以使用paypal.Button.render({...})方法ngOnInit

+0

我與OP的情況相同,但是您的解決方案對我無效 – loicb

+0

不工作,我做了 –

+0

它工作!我的人謝謝 正如你所說的,在組件(聲明前級)I「聲明」一個變量: 讓貝寶:所有; 然後,在ngOnInit()方法,我稱之爲paypal.Button.render({...])函數。 在我的模板中,我把把要包含按鈕的div和他們的工作! 謝謝。 – Thisisalexis