2

I was able to successfully implement the API on web, here is what it looks like, I have a button in a regular html file...

<div>
    <span class="radio-button radio-left" id="sandboxLinkButton">Sandbox Mode</span>
</div>

I include the script tag...

<script src="https://cdn.plaid.com/link/stable/link-initialize.js"></script>

and I include the following javascript in the html body...

<script type="text/javascript">
  var sandboxHandler = Plaid.create({
      clientName: 'SUM',
      env: 'tartan',
      product: 'auth',
      key: 'test_key',
      onSuccess: function(token) {
        //window.location = '/accounts.html?public_token=' + token;
        console.log("yes");
      },
    });

  // Open the "Institution Select" view using the sandbox Link handler.
    document.getElementById('sandboxLinkButton').onclick = function() {
      sandboxHandler.open();
    };

</script>

Now I want to do the same using angular js. I'm using an ionic framework (not that it really matters). So I first display the necessary html using the following...

app.config(function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/app');
  $stateProvider

  .state('app', {
    url: '/app',
    templateUrl: 'templates/menu.html',
    controller: 'AppCtrl'
  })
});

My menu.html file contains the following button...

 <span ng-click="create()" class="radio-button radio-left" id="sandboxLinkButton">Sandbox Mode</span>

on ng-click it reaches the following controller. I tried to implement the API in this controller to no avail...

app.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
    var sandboxHandler = Plaid.create({
    clientName: 'SUM',
    env: 'tartan',
    product: 'auth',
    key: 'test_key',
    onSuccess: function(token) {
        console.log("yes");
    },
  });

  $scope.create = function() {
    sandboxHandler.open();
  }
});

I get the error Plaid is not defined in the controller. Why is that?

EDIT

I replicated a web app version using angular and it worked. I used the following CDN instead of the ionic/angular one

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

But I still can't get it to work on my ionic web app. Has anyone else ever come across this issue?

4

2 回答 2

1

当我包含该库时,我立即在浏览器中收到以下错误:Uncaught TypeError: Cannot read property 'appendChild' of null

关于这里这里的不同库的这个错误有类似的问题,但是我无法根据这些答案解决问题。

我找到的最接近解决方案的是GitHub 上 Plaid 存储库中的此问题报告。它描述了库在放置在<head>标签中时无法工作的问题。此问题报告中的提交<body>描述了可以通过将脚本包含在标记中而不是标记中来解决此问题<head>

我建议订阅问题报告,以查看将来是否会引入其他解决方案。

所以 tldr; 尝试将<script>标签<head><body>.

于 2016-09-26T10:11:21.697 回答
0

您可以简单地使用我创建的普通角度包装器:

https://github.com/khashayar/ng-plaid

于 2016-10-26T08:22:02.243 回答