AngularJS ngRepeat语法错误

时间:2015-05-28 01:48:48

标签: javascript angularjs ng-repeat

使用AngularJS v1.3.15

我收到一个奇怪的语法错误:

  

http://errors.angularjs.org/1.3.15/ngRepeat/iexp?p0=item%20asNaNtems

这是我的模板(templateUrl):

<div class="context-menu" ng-if="showMenu">
    <div class="context-menu-item" ng-repeat="item as items" ng-class="{disabled: item.isDisabled()}">
        <a href="" ng-click="fire(item)">
            <i class="fa" ng-class="item.getIcon()"></i> {{item.getName()}}
        </a>
    </div>
</div>

该指令以该指令的控制器函数中的$scope.items = []开头:

angular.module('app').directive('atContextMenu', [
    function() {
        return {
            'templateUrl': '...',
            'controller': function($scope, $element) {
                $scope.items = [];
            }
        };
    }
]);

1 个答案:

答案 0 :(得分:5)

正如链接所示(如果您点击了链接),您获得了syntax wrong。它应该是item in collection

ng-repeat="item in items"