Interact with Angular Js by clicking on a table cell to instantly display its details in a convenient pop-up window

I am learning AngularJs and I have developed an application that displays a list of records in a table. For example: EmpNo Name 1 AAAA 2 BBBB 3 CCCC Now, my requirement is to be able to click on the EmpNo in the table and have a pop-up (new HTML Template) display with all the employee records associated with the selected EmployeeNo.

For instance, if someone clicks on EmpNo: 1, the data in the pop-up should show: EmpNo: 1 Name: AAAA Unit: XYZ Manager's Name: LLLL I would greatly appreciate it if you could provide an example. Thank you in advance. Below is some sample code snippet from my application:

HTML:

<a href ui-sref="stateTruckDetails({transferSessionId: x.transferSessionId})">{{x.location}}</a>

JavaScript: for managing application state

app.config(function($stateProvider,TRANSFER_COMPONENT_PATH) 
           { 
  $stateProvider
  .state("stateTruckDetails", 
         { url: "/transfers/truckDetails/:transferSessionId", 
          controllerAs: "truckDetailsCtrl", 
          controller: "TruckDetailsController", 
          params: { tansferSessionId: $stateProvider.transferSessionId } 
         }); 
});

The JavaScript code for the controller that my pop up needs to utilize:

app.controller('TruckDetailsController', function (transferService, $scope, dataShare, $stateParams)
               { 
  //This API call fetches details based on ID. In this case, the number 13.
  
  ctrl.GetTruckDetails = transferService.getTruckDetails(13).then(function (d) 
  { 
    $scope.data = d; 
    angular.forEach($scope.data, function (value, index) 
    { 
      console.log(index); 
    });
  }); 
}; }); }

Answer №1

To start off, make sure to bind each row to trigger a function that you need to include in your controller. For example, let's name the function openDetails. Your HTML code would resemble the following:

<tr ng-repeat="item in items"><td ng-click="openDetails(item)">Name</td></tr>

Within your controller, you must define this method:

$scope.openDetails = function(item) {
//insert popup code here
}

There are various ways to display a popup from AngularJS.

1 - A recommended approach is to incorporate Bootstrap with AngularJS - https://angular-ui.github.io/bootstrap/. Look for the 'Modal' example on their website.

2 - An alternative option is available here - http://jsfiddle.net/alexsuch/RLQhh/

3 - As a last resort, you can utilize jQuery within AngularJS.

Answer №2

Hello Diana, I truly appreciate your helpful suggestions. Fortunately, I was able to find a resolution on my own. Feel free to take a look at the plunkr demo I put together.

http://plnkr.co/edit/i1d3P8keTcMwWQ0sIn9h

Here's the fundamental concept behind it. My approach involved utilizing states to effectively showcase both parent and child pages.

app.config(function($stateProvider) {
  $stateProvider.state("managerState", {
      url: "/ManagerRecord",
      controller: "myController",
      templateUrl: 'index.html'
    })
    .state("employeeState", {
      url: "empRecords",
      parent: "managerState",
      params: {
        empId: 0
      },
      onEnter: [
        "$modal",
        function($modal) {
          $modal.open({
            controller: "EmpDetailsController",
            controllerAs: "empDetails",
            templateUrl: 'empDetails.html',
            size: 'sm'
          }).result.finally(function() {
            $stateProvider.go('^');
          });
        }
      ]
    });
});

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

I built a custom Angular application integrated with Firebase, and I'm looking for a way to allow every user to have their individual table for managing tasks

I am looking to enhance my code so that each user who is logged in has their own tasks table, which they can update and delete. Additionally, I need guidance on how to hide menu items tasks, add-tasks, logout for users who are not logged in, and display th ...

How can I set up an additional "alert" for each form when making an AJAX request?

let retrieveLoginPasswords = function (retrieveForgottenPasswords, checkLoginStatus) { $(document).ready(function () { $('#login,#lostpasswordform,#register').submit(function (e) { e.preventDefault(); $.ajax({ type: &quo ...

Cache for AngularJS $http.jsonp requests

I'm struggling with caching a JSONP request and have tested out different approaches without success. I attempted $http.jsonp(url, { cache: true }) and $http({ method: 'JSONP', url: url, cache: true }), but neither worked as expected. As a ...

AngularJS: Trouble with chain calling HTTP requests and NodeJS: Struggle with utilizing a variable across multiple HTTP calls

In my node.js file, I have both a get call and a post call that utilize the same variable initialized as an empty string outside of these calls. The post call sets the variable while the get call returns the value of the variable to the clientside angularj ...

What is the best method for generating a large number of Express.js routes quickly and efficiently?

Is there a way to efficiently generate multiple routes in Express? I am looking to create routes in the format localhost:3000/${insert address here} Should I use a for loop or is there a built-in feature in Express that can help with this? For instance, ...

Tips for customizing the IconButton appearance in material-ui

While Material-ui offers a default icon button, I am interested in customizing its design to resemble this: IconButton design needed Could you please advise me on how to make this change? Thank you. ...

Utilizing vanilla JavaScript within a React.js component: A step-by-step guide

I have implemented chartist.js in my React component, and I am facing an issue with displaying the chart on the web page. I am following the example provided at Below is the code snippet: var Chartist = { version:'0.9.5' } (function (wind ...

What are some best practices for implementing a checkbox within an editableCellTemplate?

Take a look at this code snippet: { name: 'Calculation Method', field: 'feeType', enableCellEdit: true, editableCellTemplate: 'ui-grid/dropdownEditor' ...

Separate the string by using a comma to create new lines

I'm trying to figure out how to split a string by commas and create new lines. I tried using the split and join functions, but it's only removing the commas without actually creating new lines. string='Lorem Ipsum,Lorem Ipsum,Lorem Ipsum&ap ...

The jQuery selector fails to refresh after the dynamic insertion of new elements

My selector is: $('section#attendance input:last') However, I add another input to section#attendance. I want the selector to target that new element since it should select the last element due to :last. However, for unknown reasons, it does no ...

What is the best way to prompt users to rotate their mobile phone using javascript/css?

My website is designed to be viewed horizontally only, but I am struggling to block access if the user tries to view it vertically. I can't seem to figure out how to do this on my own. Is there anyone who can offer guidance or assistance? ...

What is the best approach to creating a Typescript library that offers maximal compatibility for a wide range

My Vision I am aiming to develop a versatile library that can cater to both JavaScript and TypeScript developers for frontend applications, excluding Node.js. This means allowing JavaScript developers to utilize the library as inline script using <scri ...

I am having trouble with the browser detection not accurately identifying the browser I am currently using

Currently, I am working on a JavaScript code that will simply display the name of the browser being used to view the web page. Despite me using Safari, none of the navigators seem to recognize it as the current browser. The information displayed in my brow ...

Create and store custom variables in tinyMCE.init for future reference

After making this tweak: article_id: <?php echo $edit ?> }); I have added the code at the end of the tinyMCE.init function. My goal is to retrieve the article id within the simpleimage plugin and use it for an AJAX query to fetch a list of ...

Troubleshooting: CSS button animation not functioning

Attempting to create a hover animation for buttons on my webpage, I crafted the following CSS code: #B1 { margin: 50px; margin-top: 50px; margin-bottom: 50px; flex: 1 1 auto; padding: 20px; border: 2px solid #f7f7f7; text-align: center; te ...

Tips for customizing standard data types in TypeScript

Currently facing a challenge where I need to update a global type. Specifically, I am looking to modify the signature of the Element.prototype.animate function to make it optional. This is the approach I attempted: declare global { interface Element { ...

Stop users from modifying URLs to limit their ability to access the server's resources

Recently, I have set up node.js and express to serve html files with SSL encryption. However, I've come across an issue where users can manipulate the URL to access other HTML files on my server. For example, changing https://localhost/index.html to h ...

Having trouble accessing portlet resource URL from JavaScript in Liferay 6.2

I have been working with Liferay Portal 6.2 CE GA3 and I am facing an issue where I need to execute a custom portlet resource method from another portlet's JSP file. Below is the code snippet I am currently using. <a href ="#" onclick="myfunctio ...

Retrieving data from a nested object with varying key names through ng-repeat

My JSON object contains various properties with unique names: var definitions = { foo: { bar: {abc: '123'}, baz: 'def' }, qux: { broom: 'mop', earth: { tree: 'leaf', water: 'fi ...

It is likely that the variable is out of scope and is undefined

I have a piece of code that retrieves the description of a word in JSON format from website, which is provided by the user in the request JSON body. The issue I'm facing is that I am unable to send back the 'desc' variable in the res.send ...