2

I want to add multi dimension object in ng-init like

object({
    friends:[
        {name:John,phone:555-1276},
        {name:Mary,phone:800-BIG-MARY},
        {name:Mike,phone:555-4321},
        {name:Adam,phone:555-5678},
        {name:Julie,phone:555-8765},
        {name:Juliette,phone:555-5678}
   ],
   relative:[
       {name:Afaq,phone:555-1276},
       {name:Mary,phone:800-BIG-MARY},
       {name:Mike,phone:555-4321},
       {name:Adam,phone:555-5678},
       {name:Julie,phone:555-8765},
       {name:Juliette,phone:555-5678}
    ]
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

but when i add same like this then show me this error

"Error: [$parse:syntax] Syntax Error: Token 'Carrara' is unexpected, expecting [}] at column 1754 of the expression [object("

so what to do....

Thanks in advance...

Afaq Arif
  • 23
  • 3

1 Answers1

0

Your object structure is wrong. Try this

 var x = {
  "parent": {
   "friends": [{
     "name": "John",
     "phone": "555 - 1276"
    },
    {
     "name": "John",
     "phone": "555 - 1276"
    },
    {
     "name": "John",
     "phone": "555 - 1276"
    },
    {
     "name": "John",
     "phone": "555 - 1276"
    },
    {
     "name": "John",
     "phone": "555 - 1276"
    },
    {
     "name": "John",
     "phone": "555 - 1276"
    }
   ],
   "relative": [{
     "name": "John",
     "phone": "555 - 1276"
    },
    {
     "name": "John",
     "phone": "555 - 1276"
    },
    {
     "name": "John",
     "phone": "555 - 1276"
    },
    {
     "name": "John",
     "phone": "555 - 1276"
    },
    {
     "name": "John",
     "phone": "555 - 1276"
    },
    {
     "name": "John",
     "phone": "555 - 1276"
    }
   ]
  }
 }
 console.log(x);

You can always use Json lint to validate your json

Muhammad Usman
  • 10,039
  • 22
  • 39
  • ok but i want all add in one parent just like this parent{ "friends": [{ "name": "John", "phone": "555 - 1276" }, { "name": "John", "phone": "555 - 1276" } ], "relative": [{ "name": "John", "phone": "555 - 1276" } ] } is it possible ? – Afaq Arif Nov 03 '17 at 16:08
  • you mean all that as single object ? if yes, that's what it is already – Muhammad Usman Nov 03 '17 at 16:14
  • yes but when i add parent as a single and validate on json init it showing errorError: Parse error on line 1: "parent" { { "friends": [{ ---------^ Expecting 'EOF', '}', ':', ',', ']', got '{' – Afaq Arif Nov 03 '17 at 16:21
  • let me know if you still confused – Muhammad Usman Nov 03 '17 at 16:52