3

I'm building an Angular App and also using angular translate as it needs to be in dual languages.

I've seem to have created my JSON properly (ran it through a checker), but when I try to access items within the JSON object beyond the first level, it returns undefined.

For instance, my JSON within the angular translations is this:

$translateProvider.translations('en', {
 "SEARCH": {
    "SEARCH" : "Recherce",
    "ABILITY" : "Abilities",
    "MANAGEMENT" : "Management Competencies",
    "PERSONAL" : "Personal Suitability"
 },

 "ABILITIES": {
    "TITLE" : "Test Title here",
    "ADVISORY": {
      "TITLE" : "Advisory Skills",
      "QUESTIONS": [
        {
          "TYPE" : "A",
          "LEVEL" : "45",
          "DESCRIPTION" : "Can you tell me how awesome you are"
        },
        {
          "TYPE" : "B",
          "LEVEL" : "100",
          "DESCRIPTION" : "Tell me about your wicked project"
        }
      ]
    }
  },

  "HEADLINE": "Oh No!",
  "SUB_HEADLINE": "Looks like you are not amazing"
});   

And to begin accessing the data in the JSON object, I do

list = $translateProvider.translations('en');

Now, when outputting items in the console to see if they work I do this:

console.log(list);
var getTitle = list.HEADLINE;
var getSearch = list.SEARCH.ABILITY;
console.log(getSearch);
console.log(getTitle);

This is where it gets odd.

The 'list' returns the JSON array I specified

Getting the HEADLINE returns Oh No!

But getting list.SEARCH.ABILITY returns an undefined

What gives!? I haven't event tried to access the stuff I really want in the really nested array "ABILITIES"

Keep in mind that Angular Translate uses the format {{ 'ABILITIES.ADVISORY.TITLE' | translate }} to output the JSON onto the HTML page

Community
  • 1
  • 1
Ian Ryan Clarke
  • 268
  • 1
  • 8
  • Seems to work just fine here: http://jsfiddle.net/z1uLjg89/ Can you provide a fiddle or snippet that reproduces the issue? – JLRishe Feb 06 '15 at 18:00
  • I will try, but it is very odd that getting the headline works, but NOT the SEARCH.ABILITY. I can't think of a reason why valid JSON would work with one, but not the nested one – Ian Ryan Clarke Feb 06 '15 at 18:11
  • 7 years later, I'm experiencing the same issue. Seems no solution was found, eh? – Supreme Dolphin Apr 29 '22 at 17:10

1 Answers1

-3

try list.SEARCH["ABILITY"].value

Taryn
  • 242,637
  • 56
  • 362
  • 405