0

So I have this code :https://jsfiddle.net/afelipeor/o2qqt7ux/ and I need to be able to access the values in the object, and display the text in the html, as it is for a multi-language website. However, I can't seem to be able to, and all my research showed is that I'm declaring everything correctly.

As long as the value I need is not in a object, it works, so I know that I'm not doing things completely wrong. For example, if I create $scope.text = 'text'; and access it with {{ text }}, it works as it should.

However, I must be doing something wrong. Does anyone know what?

3
  • Please include the relevant parts of the code in your question Commented Oct 19, 2015 at 15:35
  • @LionC, I put the fiddle, because the relevant code is big enough to clutter the question. Commented Oct 19, 2015 at 15:43
  • Then create an MCVE. Stackoverflow also has its own integrated way of creating demos (code snippets). This way your question will (always) be self-contained and helpful for future readers. Commented Oct 19, 2015 at 15:48

1 Answer 1

1

From your fiddle, your data is nested in an array.

$scope.english = [
    {
        home: "home",
        about: "About Template",
        services: "Services",
        contact: "Contact",
        eng:"English",
        ptg: "Portuguese"
    }
];

You can get it to display properly like this:

         <ul class="nav navbar-nav navbar-right">
                <li><a href="#">{{english[0].home}}</a></li>
                <li><a href="#">{{english[0].about}}</a></li>
                <li><a href="#">{{english[0].services}}</a></li>
                <li>
                    <select id="navLang">
                        <option >{{english[0].eng}}</option>
                        <option>{{english[0].ptg}}</option>
                    </select>
                </li>
          </ul>
Sign up to request clarification or add additional context in comments.

3 Comments

Doesn't seem to work for me. The fiddle continued to display the same output it would before.
@AndreFelipe I recommend to look at the console output of your js fiddle. There is more than one error there
@LionC Thanks, I hadn't thought to check since my original code had none. turns out that buzzsaw was right. The problem was that it was in a array, which for me is odd, since all the examples I've seen online were as well, and didn't specify the index

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.