Currently, I am toggling a div
when the ng-click
event is triggered using the isVisible
variable. The issue I'm facing is that every time the button is clicked, the function $scope.Objectlist.push(data);
is executed. My goal is to only push the data on the initial click, but also allow it to push if a different object is being fetched. Each row has a button next to it with a unique ID passed as a parameter to the button function.
HTML:
<tr ng-repeat="object in objectlist">
<td>{{object.id}}</td>
<td><button ng-click="pushData(object.id)">View</button></td>
</tr>
JS:
$scope.objectlist = [];
$scope.isVisible = false;
$scope.pushData= function(id) {
$http.get("some variables being passed on here").success(function(data, status, headers, config){
$scope.objectlist.push(data);
}).error(function(data, status, headers, config){
alert("Error");
});
$scope.isVisible = ! $scope.isVisible;
};
Since there are multiple objects, some empty and some not, the function cannot solely rely on the length of the list for its logic.