简体   繁体   English

无法访问角度对象值

[英]Unable to access object values in angular

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. 因此,我有以下代码: https : //jsfiddle.net/afelipeor/o2qqt7ux/ ,我需要能够访问对象中的值,并在html中显示文本,因为它是针对多语言网站的。 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'; 例如,如果我创建$scope.text = 'text'; and access it with {{ text }} , it works as it should. 并使用{{ text }}对其进行访问,它应该可以正常工作。

However, I must be doing something wrong. 但是,我一定做错了。 Does anyone know what? 有人知道吗?

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM