嵌套ng-repeat的函数调用

时间:2014-11-10 07:48:52

标签: javascript angularjs

<ul class="day">
    <li ng-repeat="sessions in day">
        <ul class="table-view">
            <li class="table-view-cell" ng-repeat="(heading, session) in sessions">
                <span class="group">{{heading}}</span>
                <ul class="cell">
                    <li class="cell-content" ng-repeat="val in session" ng-click="session($event, val.id)">
                        <div class="time" style="background-color:#{{val.color}}">
                            <span>{{val.start | date:"h:mma"}}</span>
                            <span>to</span>
                            <span>{{val.end | date:"h:mma"}}</span>
                        </div>
                        <div class="session" ng-class-odd="'odd'" ng-class-even="'even'">
                            <span class="name">{{val.name}}</span>
                            <span class="room">Room: {{val.room}}</span>
                        </div>
                    </li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

我有一个嵌套的ng-repeats并且在最后一个内部循环中有一个函数调用,该函数在$ scope上定义,但是我得到了以下错误。

TypeError: object is not a function

$scope.session = function($event, id) {
   console.log(id);
};

不确定是否与ng-repeats及其范围的嵌套有关。

1 个答案:

答案 0 :(得分:0)

它与嵌套几个ng-repeats无关,但我认为它将它与从session返回的ng-repeat="(heading, session) in sessions"对象混合在一起。尝试将函数名称更改为其他内容并尝试一下。