简体   繁体   中英

function call from nested ng-repeat

<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>

I've a nested ng-repeats and within the last inner loop have a function call, the function is defined on $scope but I'm getting the following error.

TypeError: object is not a function

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

not sure if it has to do with nesting of ng-repeats and their scopes.

It has nothing to do with nesting several ng-repeats, but I think it is mixing it up with session object which returns from ng-repeat="(heading, session) in sessions" . Try to change the function name to something else and give it a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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