Delete me
Delete me

Reputation: 597

Pass angular value to common JavaScript

I am trying to pass a value from angular scope to common JavaScript.

The JavaScript is like this

<script type="text/javascript">
var epaycode = null;
var epaybuysum  = null;
paymentwindow = new PaymentWindow({
'merchantnumber': epaycode,
'amount': epaybuysum,
'currency': "DKK",
'windowstate': "4",
'paymentcollection': "1",
'iframeheight': "250",
'iframewidth': "500"
});
paymentwindow.append('payment-div');
setTimeout(function(){
    paymentwindow.open();
}, 1000);

The angular controller code is like this

    $scope.showpay = function () {
    $window.epaybuysum = $scope.buysum * 100;
    $window.epaycode = $scope.ePayCode;
};

The Angular showpay() function is called after the common JavaScript is initialized. The buysum and ePayCode is set earlier in the program. They have value and is tested with console.log().

Why doesn't the epaybuysum and epaycode getting transferred to the common JavaScript? Is there any other solutions to passing values to common JavaScript from Angular controllers?

Upvotes: 1

Views: 205

Answers (2)

Sidharth Panwar
Sidharth Panwar

Reputation: 4654

Try this:

(function (angular, epaycode) {  
  'use strict';  
  var module = angular.module('abc', []);  
  //Your controller etc.  
  }  
})(angular, epaycode);

Updated
The plunker in the comments section shows how you can do this.

Upvotes: 0

Ana F
Ana F

Reputation: 641

Have a look at this plunker: http://plnkr.co/edit/lQiXpObbWuG84CNbcZt2?p=preview

 <div ng-controller="MainCtrl">
      <input ng-model="buyCode">
      <input ng-model="buySum">
      <p>{{buyCode}} ... {{buySum}}</p>

      <button ng-click="showPay()">call showPay</button>
 </div>

 <button onclick="buttonClick()">Console.log</button>

The first button calls your showPay function(the one on scope). The second button calls console.log (outside the angular controller, simple js). For this simple usecase it seems to work as expected. How are you calling showPay function?

Upvotes: 2

Related Questions