-1

Hi I have this data in JSON form, and I want to convert this data of option into json so that i can call optionName, optionSubName in a view part of angularjs

    [
    {
      "heading": "MakeUp Type / Selection",
      "option": "{"optionName":"Bridal Makeup","optionSubName":"Engagement,Tika / Godh Bharai,Ring Ceremony","optionDesc":""}",
      "values": null
    },
    {
      "heading": "Makeup Type",
      "option": "{"optionName":"Experienced","optionSubName":"","optionDesc":{"products":"Bobbie Brown,Makeup Forever and Premium Makeup Products","Makeup_Include":"Straightening,Blow Drys,Tong Curls,Updo's","Drapping":"Yes","Lashes":"Yes","Nail_Polish_Change":"Yes","Extension_Available":"Yes","Airbrush_Available":"Yes"}}",
      "values": null
    }
  ]

I have already tried this but this is not working by using ng-repeat i have using this {{data.option.optionName | JSON}} but this is not working in my view part of angularjs, Please help me out how to reach at my goal ?

1 Answers1

0

Use AngularJS forEach:

angular.forEach(object, iterator, [context])

object: The object interate over.
iterator: The iterator function or the code.
context: Object to become context (using this) for the iterator function.

var app = angular.module('app', []);
    app.controller('AppController', ['$scope', '$http', 
      function($scope, $http) {
        $http.get('json/array.json').success(function(data) {
            $scope.array = data; 
              angular.forEach($scope.array, function(x){
                   console.log(x.optionName);  
               })
            });
        });

      }
    ]); 
user-9725874
  • 831
  • 9
  • 15
  • Sorry Sir, but that's not working for me .. but your answer give me an idea how to achieve my goals, I've used `ng-init` and take that json in my another variable to achieve my goal, but thanks for helping me !! thank you so much – utkarsh tiwari Mar 08 '19 at 09:29
  • The `.success` method had been [removed from the AngularJS framework](https://stackoverflow.com/questions/35329384/why-are-angularjs-http-success-error-methods-deprecated-removed-from-v1-6/35331339#35331339). – georgeawg May 22 '19 at 17:17