angularjs ng-click不使用事件

时间:2016-09-08 10:42:32

标签: jquery html angularjs

我是angularjs的新手,我在ng-click事件中遇到问题。我发现,问题是由于点击事件,但不知道如何纠正它。

点击按钮时抛出错误:

  

错误:未定义$ event

HTML

<div class="form-group" data-ng-repeat="data in result[5]" >
    <span>
        <img ng-src={{data.image}} width="108" height="108">
    </span>
    <span>
        <input type="button" ng-click="removeProductImage($event, data.id_image)" class="btn btn-danger" value="Delete this image"></input>
    </span>
</div>      

app.js

$scope.removeProductImage = function(event,photo) {
    var target = $event.target;
    var container = $(target).parent().parent();
    //container.remove();
    return $http.get("catalog-ajax.php",{params:{type:11, id_image: photo}}).then(function(response){
      console.log(response);
    });
};

3 个答案:

答案 0 :(得分:0)

使用$ event代替事件

 $scope.removeProductImage = function($event,photo) {
var target = $event.target;
var container = $(target).parent().parent();
//container.remove();
return $http.get("catalog-ajax.php",{params:{type:11, id_image: photo}}).then(function(response){
  console.log(response);
});
};

答案 1 :(得分:0)

问题出在这一部分:

select agegroup,
       sum(case when category = 'music' and day = 'Fri' then appcount else 0 end) as music_fri,
       sum(case when category = 'music' and day = 'Mon' then appcount else 0 end) as music_mon,
       . . .
from 
group by agegroup;

将其更改为$scope.removeProductImage = function($event,photo) { var target = $event.target; var container = $(target).parent().parent(); //container.remove(); return $http.get("catalog-ajax.php",{params:{type:11, id_image: photo}}).then(function(response){ console.log(response); }); }; 而不是$event

答案 2 :(得分:0)

您的参数名称和方法中的变量是不同的。像这样改变

$scope.removeProductImage = function($event,photo) {
    var target = $event.target;
    var container = $(target).parent().parent();
    //container.remove();
    return $http.get("catalog-ajax.php",{params:{type:11, id_image: photo}}).then(function(response){
      console.log(response);
    });
};