AngularJS伍重复功能未正常工作 [英] AngularJS Ng-repeat is not working as expected

查看:222
本文介绍了AngularJS伍重复功能未正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我可以访问所有的元素从我的范围,因为数据模型的到来,我也可以看到在Chrome控制台的范围元素,一个奇怪的问题,但是当我尝试使用NG-repeat语句中的模型它不工作,它只是通过 vm.menu.items 不循环。下面是我简单的code:

I'm having a weird issue, I can access all the elements coming from my scope as data model, also I can see the scope elements in the Chrome console, but when I try using the model within a ng-repeat statement it does not work, it just does not loop through the vm.menu.items. Below is my simple code:

<body ng-controller="mainController">
    <div ng-controller="app.views.layout.header as vm">

        <p>{{vm.currentMenuName}} {{vm.menu.items[0].displayName}} {{vm.menu.items[1].displayName}}</p>  **<<----- IT works!**

        <ul>
            <li ng-repeat="menuItem in vm.menu.items">
                <span>Not working! </span>{{menuItem.displayName}}
            </li>
        </ul>

    </div>
</body>

我还是pretty新的角度,使点我到正确的方向任何帮助将大大AP preciated。

I'm still pretty new to angular, so any help that point me into the right direction will be greatly appreciated.

推荐答案

我删除了虚拟机。在你的HTML,一切按预期工作。

I removed the 'vm.' in your html and everything works as expected

<body ng-controller="mainController">
   <div ng-controller="app.views.layout.header as vm">

    <p>{{currentMenuName}} {{menu.items[0].displayName}} {{menu.items[1].displayName}}</p>

    <ul>
        <li ng-repeat="menuItem in menu.items">
            <span>Not working! </span>{{menuItem.displayName}}
        </li>
    </ul>

</div>

http://plnkr.co/edit/1BtC8p1ViqKXSbCWE3Kj?p=$p$ PVIEW

或者你能给我们'这'在你的控制器,而不是$范围(见 HTTP :?//plnkr.co/edit/1BtC8p1ViqKXSbCWE3Kj p = preVIEW

Or you can us 'this' in your controller instead of $scope (see http://plnkr.co/edit/1BtC8p1ViqKXSbCWE3Kj?p=preview

这篇关于AngularJS伍重复功能未正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆