I am currently learning to code with Angular.js and I am doing a project where I load information with Ajax queries.
To make it short, I have three levels of data
-- Skills (competences)
--- Indicators (indicateurs)
---- Results (resultats)
I have a first request that tracks Skills and Indicator for the current skill.
HTML
<div ng-controller="AdminController" data-ng-init="listAllCompetences()">
<!-- Level 1 -->
<div data-ng-repeat="competence in competences" class="content level1 topcompetence" id="competence_{{competence.Competence.id}}">
<div class="level1_title_box">
<h3 class="h3 titre_competence" ng-hide="editorEnabled">{{$index + 1}} - {{competence.Competence.description}} </h3>
</div>
<p><b>Indicateurs de performances : </b></p>
<!-- Level 2 -->
<div data-ng-repeat="indicateur in competence.Indicateur" class="content level2" id="indicateur_{{indicateur.id}}">
<div class="level2_title_box">
<h4>{{$index + 1}} - {{indicateur.description}}</h4>
</div>
<p><b>Results : </b></p>
<p><a ng-click="listAllRestulatsByIndicateurId(indicateur.id)" href="javascript:void(0);">Click here to show results</a></p>
<!-- Level 3 -->
Level 3 should be displayed there...
<!-- End Level 3 -->
<pre>{{resultatsAttendusCallback}} {{resultatsAttendusCallback.length}}</pre>
</div>
<!-- End Level 2 -->
</div>
<!-- End Level 1-->
</div>
When I click on listAllRestulatsByIndicateurId(indicateur.id); function, there is an Ajax request that get all the results for the given indicator.
The point where I have not figured it out yet is how am I supposed to know where to output this since I can have a lot of Indicators.
My Angular function
$scope.listAllRestulatsByIndicateurId = function(indicateurID) {
console.log(indicateurID);
var req_resultats_by_indicateur = {
method: 'POST',
url: '../api/resultatAttendus/listByIndicateur',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: {
indicateur_id: indicateurID
}
}
console.log(req_resultats_by_indicateur);
$http(req_resultats_by_indicateur).then(function successCallback(callback) {
if(callback.data.status == 'success') {
$scope.resultatsAttendusCallback = callback.data.data;
console.log(callback);
}
if(callback.data.status == 'error') {
console.log(callback)
}
});
}
Note: The use of callback, may be bad as I named it. It is the returned array from my ajax call.
This line $scope.resultatsAttendusCallback = callback.data.data; give me the array of results with the indicator ID as parent.
But when I execute this function, all my {{resultatsAttendusCallback}} or Results spaces are writing the array. I just want to get the result to be printed in the indicator ID I clicked.
Is there any way to attribute any sort of ID or Class name to those element so I could know on which element to work and get the angular callback working?

callback. Bad name choice. What exactly are you wanting to do withresultatsAttendusCallback? In javascriptcallbackis a use case term for a function