简体   繁体   中英

angularjs ng-click function parameter not working with ng-repeat

The event.id is rendered/compiled correctly in the html text but the function does not recieve it correctly. even when it shows it correctly in the source, whats going on here?

<span ng-repeat="event in [{"id":"dxczhlyvmblc","name":"4 on 4 - Pickup","venuename":"Box Hill Aqualink","numspotsleft":"<strong>Spots now open<\/strong>","day":"28","dayname":"Wednesday"}]">
    <button ng-click="toggleModal('<% event.id %>')">More detail = <% event.id %></button>
</span>

在此输入图像描述

shopApp.controller('MainController', function($scope, $http, $q){
    $scope.toggleModal = function(eventId){
        console.log(eventId+" toggle");
    };})

Note i am using <% in stead of {{ because of the templating engine.

Arguments for functions in view don't use angular templating expressions.

Change to:

ng-click="toggleModal(event.id)"

You may also find it more convenient to pass the whole object in if you want to pass that object to a modal controller for example

因为您想将toggleModal的值传递给toggleModal函数:

<button ng-click="toggleModal(event.id)">More detail = <% event.id %></button>

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