I'm facing a challenge with a seemingly simple task.
Within an ng-repeat, I have a table of events. My goal is to enable users to click on the event name and view detailed information in a modal window.
To achieve this, I have set up an
ng-click="eventDetails(objectId)"
function linked to the event title. In my controller, the code looks like this:
app.controller('viewEventRequestsController', function($scope, EventFactory){
// Fetching a list of events, each containing an objectId property
EventFactory.query(function(response){
$scope.events = response.results;
});
// Function triggered when clicking an event name
$scope.eventDetails = function(objectId){
$scope.modalOn = true;
$scope.modal = EventFactory.get({ objectId: objectId });
console.log($scope.modal)
}
});
This snippet demonstrates part of my markup:
<tr ng-repeat="items in events | filter:filter | orderBy:sort:reverse">
<td>
<a ng-click="eventDetails(objectId)">{{items.Name}}</a>
</td>
However, the issue arises as console.log($scope.modal);
returns the entire array of objects instead of just the selected one.
In another section of my application, using
$scope.events = EventFactory.get({ objectId: $routeParams.objectId });
works correctly. Unfortunately, this approach doesn't fit my current needs since I must display event details in a modal instead of redirecting to a separate page. Therefore, I cannot employ $routeParams
this time.
Are there any suggestions on how to overcome this obstacle?