veeran veeran - 3 months ago 23
AngularJS Question

angularjs ng-click not working with event

I am new to angularjs, i am facing issue in ng-click event,i found the issue is due to click event but don't know how to rectify it.Error thrown on clicking button: Error: $event is not defined

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);
});
};

Answer

The problem is with this part:

$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);
    });
};

Change it to $event instead of event.