Я новичок в angularjs, у меня проблема с событием ng-click. Я обнаружил, что проблема связана с событием щелчка, но не знаю, как его исправить.

Ошибка при нажатии кнопки:

Ошибка: событие $ не определено

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);
    });
};
0
veeran 8 Сен 2016 в 13:42

3 ответа

Лучший ответ

Проблема в этой части:

$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 вместо event.

0
Endre Simo 8 Сен 2016 в 10:49

Используйте $ event вместо 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);
});
};
0
Hassan Tariq 8 Сен 2016 в 10:48

Имя вашего параметра и переменная в методах отличаются. Изменить как это

$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);
    });
};
0
Tharsan Sivakumar 8 Сен 2016 в 10:49