0

I'm going to add some data in an array to $http service in angularjs. The way I add them to service is mentioned below (and it works properly)

var inputValueArray  = new Array($scope.formdata);

I can get data by index zero in my api. But I want to get by named index. So, I do something like this:

var inputValueArray  = new Array();
inputValueArray["myIndex"] = $scope.formData;

But, in api I get empty array. Then I did this solution:

var inputValueArray = {"myIndex" : $scope.formData};

Now I get Maximum call stack size exceeded error. In both , I use $_POST to get data. I mean I'm sending data by $.param() like this :

data: $.param({ mydata:inputValueArray , csrf_token: myTokenKey})

Any idea would highly appreciated.

1 Answer 1

0

According to ECMAScript 2015 (ES6) standard javascript has a Map implementation.

link

Example:

var myMap = new Map();

var keyString = "a string",
    keyObj = {},
    keyFunc = function () {};

// setting the values
myMap.set(keyString, "value associated with 'a string'");
myMap.set(keyObj, "value associated with keyObj");
myMap.set(keyFunc, "value associated with keyFunc");

myMap.size; // 3

// getting the values
myMap.get(keyString);    // "value associated with 'a string'"
myMap.get(keyObj);       // "value associated with keyObj"
myMap.get(keyFunc);      // "value associated with keyFunc"

myMap.get("a string");   // "value associated with 'a string'"
                         // because keyString === 'a string'
myMap.get({});           // undefined, because keyObj !== {}
myMap.get(function() {}) // undefined, because keyFunc !== function () {}
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. But again the same problem.
please upload your code to JSFiddle or other application, and I will try to help you.
I get a very stupid error in JSFiddle. I can't instantiate my app. Would you please check this? jsfiddle.net/6kstm3e8/25
How did you solved that error? your code was similar to mine. Here is all codes : jsfiddle.net/6kstm3e8/34 , But I get this error : ReferenceError: $ is not defined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.