Récupérer un data-id={{item.id}} d'un button pour envoyer une requete .php?id= via $http
Bonjour,
Cela fait 2 jours que je me prend la tête a essayer d'extraire mon data-id='{{item.id}}' d'un button (voir html) afin de l'utiliser pour envoyer une requete vers ma mysql grace a $http get page.php?id=+id (voir js) j'ai tout essayer mais mon alert me renvoi comme id (undefined)
Où est le problème svp je n'y connais pas grand chose sur angularjs je viens de m'y mettre j'ai tester plusieurs solution mais rien n'y fait :(
'ai aussi essayé toute les solution trouver sur le net toujours pareil et dans mon code source l'id s'affiche bien (data-id='554')
Voilà j'espère que vous m'aurez compris merci a tous
HTML
Code:
1 2 3 4
|
<button tooltip-placement="top" tooltip-append-to-body="true" tooltip="Marquer comme lu" class="btn-mark-read" data-id='{{item.id}}' ng-if="!item.seen" ng-click="setSeen(item, $event)"><i class="glyphicon glyphicon-unchecked"></i></button>
// LE CODE SOURCE M'AFFICHE BIEN data-id='554' MAIS COMMENT ENVOYER CE CHIFFRE A MON VAR ID = |
JS
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
angular
.module('theme.core.notifications_controller', [])
.controller('NotificationsController', ['$scope', '$filter', '$http', function($scope, $filter, $http) {
'use strict';
$scope.notifications = [
text: 'Bienvenue',
time: '4m',
class: 'notification-success',
iconClasses: 'glyphicon glyphicon-ok',
id: '554',
seen: true
];
$scope.setSeen = function(item, $event) {
var id = angular.element(item).data('id'); // CETTE LIGNE NE RECUPERE PAS MON ID data-id='{{id}}'
$http ({
method: 'GET',
url: 'make_viewnotif.php?view=true&id='+ id , // URL DE MON FICHIER INCLUANT L'ID POUR LA MODIFICATION MYSQL
}).then(function successCallback(response) {
alert(id); // L'ALERT ME RETOURN UNDEFINED
$event.preventDefault();
$event.stopPropagation();
item.seen = true;
}, function errorCallback(response) {
alert("Une erreur est survenue, merci de ré-éssayer plus tard.");
});
};
$scope.setUnseen = function(item, $event) {
$event.preventDefault();
$event.stopPropagation();
item.seen = false;
};
$scope.setSeenAll = function($event) {
$event.preventDefault();
$event.stopPropagation();
angular.forEach($scope.notifications, function(item) {
item.seen = true;
});
};
$scope.unseenCount = $filter('filter')($scope.notifications, {
seen: false
}).length;
$scope.$watch('notifications', function(notifications) {
$scope.unseenCount = $filter('filter')(notifications, {
seen: false
}).length;
}, true);
}]); |