2016-11-19 59 views
2

我正在研究連接到Quickbooks的角度2應用程序,並且想要包含由intuit(具有一些內置功能)提供的按鈕。在標準的HTML,這將是這樣的:Angular 2將連接添加到Intuit按鈕

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ipp=""> 
<head><meta http-equiv="Content-Type" 
      content="text/html; charset=ISO-8859-1"> 
    <title>QBO Connect</title> 

    <script type="text/javascript"  src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere-1.3.3.js"> </script> 
    <script> 
    intuit.ipp.anywhere.setup({ 
     grantUrl: 'http://localhost:3000/requestToken', 
     datasources: { 
     quickbooks : true, // set to false if NOT using Quickbooks API 
     payments : false // set to true if using Payments API 
     } 
    }); 
    </script> 
</head> 
<body> 
<ipp:connectToIntuit></ipp:connectToIntuit> 
<ipp:login href= 'http://localhost:3000/login/authenticate'  type="horizontal"></ipp:login> 
</body> 
</html> 

但角2的模板不支持腳本標記,我無法弄清楚如何添加自定義標籤。如果有人可以請讓我知道如何將其轉換成角度2,這將是偉大的。由於

回答

1

我設法得到它這樣做(醜陋和噁心)的方式:

  1. 負載Intuit的JS LIB在index.html爲模塊

<head> <script type="text/javascript" src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"></script></head>

  • 我無法在名稱中創建冒號或冒號的組件,或者名稱空間 - 角模板解析器剛剛刪除ipp:從名字只留下connecttointuit之名,所以在我的組件,我不得不元素手動追加到DOM中ngOnInit鉤:

    @ViewChild('qbContainer') qbContainer; ngOnInit(): void { this.qbContainer.nativeElement .appendChild(document.createElement('ipp:connecttointuit')); }

  • 其中qbContainer在模板中定義如下:

    <div id="qb-button-container" #qbContainer></div>

  • 然後我打電話window['intuit'].ipp.anywhere.init();得到它發現這個元素,並結合自身實際按鈕取代。
  • 我希望有一個更好的解決方案_(ツ)_ /¯

    +0

    這幫了我很大的,謝謝:)有點兒吮吸那角2條出不告訴你冒號前元素的部分。花了我一段時間來弄清楚發生了什麼事。 – ShaneK