Search code examples
javascriptarraysjsontypeaheadangular-ui-typeahead

How to create following type of json that will usefull in type ahead with angular js


I have successfully implement type ahead using angular js using this codepen.

Now my data is dynamic so I want to create my own json that should looks something like following:

$scope.states = [
      {
          name: "ABCD",
          id: "AB"
      },
      {
          name: "XYZ",
          id: "XY"
      },
      {
          name: "OPQR",
          id: "OP"
      },
      {
          name: "LMNO",
          id: "LM"
      },
      {
          name: "KLM",
          id: "KL"
      }
    ];

How to create like above json and store in $scope variable so I can access it using name and id separately.

Please help me...!!


Solution

  • I am giving by my own now cause I got it little bit late.

    Solution is I have pushed the data wrong I have solved it like:

    $scope.states.push({
                            name: "string",
                            id: int,
                        });
    

    and I got it.