javascript - angularJS error: Error: n.replace is not a function -


i using third-party js file interact external api, tokenizes data before sending. in simple test page, function works fine , returns token. however, when try implement actual app uses angularjs, keeps failing error: "error: n.replace not function".

here simple test script works:

    // click event handler $('#form-submit').click(function (e) {     e.preventdefault();      $('#response').hide();      var payload = {         api_id: 'abcde123',         var1: $('#var1').val(),         var2: $('#var2').val(),         var3: $('#var3').val(),         var4: $('#var4').val()     };      // tokenize data     vendorscript.createtoken(payload)       .success(ontokencreated)       .error(ontokenfailed);  }); 

and here angular code throws error:

app = angular.module 'myapp'  myctrl = ($scope, $http, $window, $q) ->    myformparams = ->     api_id: 'abcde123'     var1: $scope.var1     var2: $scope.var2     var3: $scope.var3     var4: $scope.var4    ontokencreated = (response) ->      # real transaction here using onetime_token      alert("the onetime_token created: " + response.onetime_token)      $scope.checkoutpromise.resolve()    ontokenfailed = (response) ->      # real transaction here using onetime_token      alert("getting onetime_token failed: " + response.onetime_token)      $scope.checkoutpromise.resolve()    $scope.submitform = ->     return if $scope.isprocessingorder      $scope.isprocessingorder = true     $scope.checkoutpromise = $q.defer()     $scope.checkoutpromise.promise.then ->       $scope.isprocessingorder = false      vendorscript.createtoken(myformparams())       .success(ontokencreated)       .error(ontokenfailed);    app.controller 'myctrl', ['$scope', '$http', '$window', '$q', myctrl] 

so, i've read var.replace error being caused var not being string (thus not have replace method); however, when debug original script, payload passed object, myformparams() passes object. furthermore, when stringify myformparams() ( i.e. "json.stringify(myformparams())" ), tokenization function fails.

been banging head on bit; help/insight appreciated!


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -