Я новичок в 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);
});
};
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
.
Используйте $ 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);
});
};
Имя вашего параметра и переменная в методах отличаются. Изменить как это
$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);
});
};
Похожие вопросы
Новые вопросы
jquery
jQuery — это библиотека JavaScript. Также рассмотрите возможность добавления тега JavaScript. jQuery — это популярная кросс-браузерная библиотека JavaScript, которая упрощает обход объектной модели документа (DOM), обработку событий, анимацию и взаимодействие AJAX, сводя к минимуму расхождения между браузерами. Вопрос с тегом jQuery должен быть связан с jQuery, поэтому jQuery должен использоваться рассматриваемым кодом, и в вопросе должны быть как минимум элементы, связанные с использованием jQuery.