简体   繁体   English

angularjs ng-click函数参数不能与ng-repeat一起使用

[英]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. event.id在html文本中正确呈现/编译,但函数无法正确接收。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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