Utilizing AngularJS repeaters to pass information into Foundation modals

I am currently working on creating a "members" page for a website that will feature 3 columns of pictures and names for each member. My goal is to allow users to click on a specific member's picture to access more detailed information about them through Foundation's modal feature. I have set up a repeater to display the pictures, but I am facing a challenge in passing the correct member data into the modal so that when a user clicks on person A, they will see person A's data displayed.

Here is an overview of my progress so far:

The member details are stored as a JSON list in a file named members.json:

{
    "current" :  [
    {
        "name": "Bob",
        "pic": "http://www.placehold.it/300x300",
        "id": "blah",
        "position": "position 1",
        "bio": "Hi I am Bob"
    },

    {
        "name": "Bobby",
        "pic": "http://www.placehold.it/300x300",
        "id": "blah",
        "position": "position 2",
        "bio": "Hi I am Bobby"
    }
    ]
}

Below is the code snippet for the controller that utilizes the JSON file:

var app = angular.module('app').controller('memberCtrl', ['$scope', '$http', function ($scope, $http) {
    'use strict';

    $http.get('/data/members.json').success(function(data) {
          // logic to set up the members data for display
    });
}]);

And here is the HTML code section related to the modal:

<div ng-controller="memberCtrl" id="myModal" class="reveal-modal">
    <!-- Modal content structure -->
</div>


<div ng-controller="memberCtrl">
      <!-- Iterating through member profiles to create the 3-column layout -->
</div>

Answer №1

Include ng-click attribute within the image tag:

<img ng-src="{{members.current[$parent.$index * numColumns + $index].pic}}" 
     ng-click="loadMember(members.current[$parent.$index * numColumns + $index]);"/>

Implement the following function in the controller:

$scope.loadMember = function (member) {
    //accessing the current member should be possible
    console.log(member);
}

View Demo on jsFiddle

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Concealing a section of a table with JavaScript while preserving the original table structure

I made some adjustments to the script tag: $(document).ready(function) { Now, the evenTd's are hidden correctly. Here is the table with the code provided: <table> <tr> <td>itemOne</td> <td class="even ...

Using the AngularJS framework to gain access to the ng-model of a select input within

I have a select element on my webpage: <select multiple id="userId" class="form-control" ng-model="ctrl.selectData.currentUser" ng-options="user.id as user.firstName + ' ' + user.lastName for user in ctrl.users" ...

Key press event not firing as expected

<multiselect v-model="value" :options="websites" label="url" track-by="url" :allow-empty="false" class="header-select mr-3" v-on:keyup.enter="submit"></multiselect> My requi ...

Is it possible for the $.post function to overwrite variables within the parent function?

Recently, I delved into the world of JavaScript and my understanding is quite limited at this point. So, please bear with me as I learn :-) I am working on a basic booking system that saves dates and user IDs in MySQL. The system checks if a particular da ...

"Utilizing GroupBy and Sum functions for data aggregation in Prisma

I am currently working with a Prisma schema designed for a MongoDB database model orders { id String @id @default(auto()) @map("_id") @db.ObjectId totalAmount Int createdAt DateTime @db.Date } My ...

The problem with reflect-metadata - __webpack_require__ arises from the absence of the 'Require' definition

I'm facing an issue while trying to launch my angular app in Visual Studio. It seems to be stuck on the "Loading..." section. Upon checking Chrome's error console, I came across the following error: https://i.sstatic.net/1aSZT.jpg Uncaught R ...

Looking up routes on Google Maps - Response from the Directions service

Using the Google Maps API to retrieve a route between two points. The response from Directions Service is used to render directions in HTML: $scope.directionsDisplay = new maps.DirectionsRenderer(); var directionsService = new maps.DirectionsService(); ...

Using getElementsByTagName in E4X code involves querying for specific

Is it possible to retrieve an array of elements in E4X for an unknown tagname, similar to how the DOMs getElementsByTagName function works, within a function? My initial idea was: (function (doc, tag) { return doc..[tag]; }) Can this be achieved? ...

Utilize ngModel in conjunction with the contenteditable attribute

I am trying to bind a model with a tag that has contenteditable=true However, it seems like ngModel only functions with input, textarea or select elements: https://docs.angularjs.org/api/ng/directive/ngModel This is why the following code does not work ...

Unable to execute event.target.blur() function as expected

I am facing an issue with my Bootstrap buttons setup. Here is an example: <button :disabled="page === lastPage" type="button" class="btn btn-default" @click="getPage(lastPage)"> <span class="glyphicon glyphicon-forward"></span> </ ...

The error message: "Trying to access property 'get' of an undefined object"

$http.get('/contactList'). success(function(data){ console.log('received data from http get'); }). error(function(data) { $scope.error = true; $scope.data = data; return 'error message'; }); There seems to be ...

Is there a way to display my current connected clients to a new client using socket.io?

I am currently working on a project involving socket.io. Upon connecting to a new socket, my input username is displayed in the "usersDiv" where all clients are supposed to be listed. However, I've noticed that when I open another tab and input my nam ...

Troubleshooting problem with JSON decoding in PHP and json_encode

Encountering an issue when parsing JSON received from a PHP backend. In my PHP code, I have an array that I send using json_encode: $result[] = (object) array('src' => "{$mergedFile}", 'thumb_src' => "{$thumb_file}"); echo json_e ...

"Exploring the process of integrating angular-xeditable into a MeanJS project

I recently attempted to install angular-xeditable from the link provided, but encountered issues while trying to reference the JavaScript files in layout.html after downloading it with bower. According to the documentation, these files should be added auto ...

Ways to utilize the Math.max and Math.min functions within an Array

Attempting to use this approach on an array to retrieve both the minimum and maximum values proved unsuccessful. var array = [3, 6, 1, 5, 0, -2, 3]; var min = Math.min( array ); var max = Math.max( array ); document.write(max); ...

Is it feasible to trigger a modal to open from a source external to the Vue

How can a component be made reusable by calling a method from outside the component? Currently, I include a button to open the modal in a template slot: index.php <modal> <template slot="button"> <button class="btn">Open mo ...

Activate Vuetify to toggle a data object in an array list when the mouse hovers over

I'm currently working on a project where I need to toggle a Vuetify badge element for each item in an array when the containing div is hovered over. While I've been able to achieve a similar effect using CSS in a v-for loop with an array list, I ...

Is there a way to simultaneously send a file and additional information in Flask?

Below is the code I am using to upload a file to Flask. Client Side: <form id="upload-file" method="post" enctype="multipart/form-data"> <fieldset> <label for="file">Select a file</label> <input name="file8" ...

Starting a line series from the beginning of the y-axis on a bar chart using chart.js

We have a new request from the business regarding the implementation of chart.js. Take a look at the image below, which shows a combination of bar and line charts. The line chart contains only a few data points. https://i.sstatic.net/mCSlR.png Within th ...

Enhancing the efficiency of nested ajax calls loop

Disclaimer: While the final result is successful, I am struggling to comprehend the sequence in which a loop of nested ajax calls operates. Essentially, I have two ajax calls that fetch data from an external API using curl GET requests. They both rely on ...