Angular- Product Details

I'm currently expanding my knowledge of angular (utilizing the ionic framework with phone gap included) and I'm working on developing a single application that displays a list of data. When a user clicks on an item in the list, I want to show the details for that specific item. While I have successfully displayed all the items in the list, I am facing difficulties in showing the details for a single item. The root of the issue seems to be related to $routeParams, but I'm struggling to pinpoint exactly what is causing the problem.

app.js

angular.module('app', ['ionic', 'app.controllers'])

.config(function($stateProvider, $urlRouterProvider, $routeProvider) {

    .state('app.list', {
      url: '/list',
      views: {
        'menuContent' :{
          templateUrl: "templates/list.html"
        }
      }
    })

    .state('app.staff', {
      url: '/staff/:staffid',
      views: {
        'menuContent' :{
          templateUrl: "templates/staff-details.html",
          controller: 'StaffDetailsCtrl'
        },
      }
    })

});

controllers.js

.controller('FooCtrl', function($scope) {
   $scope.staff = [
       { id: 1, name: 'Jim', color: 'red' },
       { id: 2, name: 'Bob', color: 'blue' },
       { id: 3, name: 'Peter', color: 'yellow' }
       /*... etc... */
   ];
});

// Review Controller
.controller('StaffDetailsCtrl', function($scope, $routeParams) {

  // Get staff
  alert('yeeeees');
  var id = $routeParams.staffid;
  $scope.staff = $scope.staff.get(id);

});

staff-details.html

{{staff.id}}<br />
{{staff.name}}<br />
{{staff.color}}

UPDATE

Link to Plunker.

Answer №1

If you're working with the angular-ui-router, it's important to remember to inject $stateParams rather than $routeParams. Your code should be structured like this:

angular.module('app', ['ionic', 'app.controllers'])
    .config(function($stateProvider, $urlRouterProvider) {

        $stateProvider
            .state('app.staff', {
                url: '/staff/:staffid',
                views: {
                    'menuContent' :{
                        templateUrl: "templates/staff-details.html",
                        controller: 'StaffDetailsCtrl'
                    },
                 }
            })
 });

// Staff Details Controller
.controller('StaffDetailsCtrl', function($scope, $stateParams) {
     // Get staff details
    alert('yeeeees');
    var id = $stateParams.staffid;
    $scope.staff = $scope.getStaff(id);
});

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

To include a Material Icon in your React-Toastify notification

This is an example of code located in a specific folder. While trying to incorporate a material Icon, an error has been encountered. 'React' must be in scope when using JSX import { toast } from 'react-toastify'; import ErrorIcon from ...

How can an array be concatenated using tabs?

I am currently in the process of integrating with an old system that requires a value to be sent via a GET request as a tab delimited string. I have my data stored in an array, but I am facing difficulty when attempting to properly format it using the join ...

The div layer is positioned above the flash object

I have successfully implemented a method where I position a div over a webpage containing a flash object. This absolutely positioned div has a high z-index and captures click events. The main goal is to trigger the click event on the div when the flash obj ...

Encountering an error while including ngmin in the r.js build file

Currently, I am attempting to utilize ngmin with requirejs's r.js as outlined in a guide found here. Unfortunately, I have encountered issues and cannot seem to make it work. Despite installing both ngmin and requirejs globally and locally using npm, ...

How can you assign a value to an HTML Input by dragging an SVG shape or canvas?

I am currently in the process of creating a user interface for setting pricing parameters. There are three categories that need to be visually represented, along with two sliders to determine suggested Buy/Sell prices. To demonstrate my progress so far, I ...

Can I rely on setTimeout to guarantee the execution of a task in NodeJS?

I am working on a REST backend using ExpressJS. One of the functionalities of this backend is to allow users to upload file assets, but these files should only exist for 10 minutes. Is it secure to rely on setTimeout to automatically delete the uploaded f ...

Configuring IP Whitelisting for Firebase Cloud Functions with MongoDB Cluster

What is the process for including my Firebase Cloud Functions in the IP whitelist of my MongoDB cluster? Error Message: ...

Error: Property 'html' is undefined - AJAX response must be displayed only in a specific div

I encountered an issue: Uncaught TypeError: Cannot read property 'html' of undefined I am working on implementing a voting system for each video on my webpage from a database. I have successfully integrated it using AJAX, but the problem is ...

Tips on conducting a statistical analysis without having to wait for the completion of an AJAX response

I am looking to track the number of clicks on a specific div with the id #counter and then redirect the user to a different website. To achieve this, I have implemented an ajax call on the click event of the #counter div. Upon successful completion of the ...

Invert the motion within a photo carousel

Is there anyone who can assist me with creating a unique photo slider using HTML, CSS, and JS? Currently, it includes various elements such as navigation arrows, dots, and an autoplay function. The timer is reset whenever the arrows or dots are clicked. Ev ...

Concealing a button once the collapse feature is toggled in Bootstrap

The following code snippet from the bootstrap website demonstrates how to use collapse functionality: <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample"> Link with href & ...

How can JavaScript onClick function receive both the name and value?

My current challenge involves a function designed to disable a group of checkboxes if they are not checked. Originally, this function was set to work onClick(), with one argument being passed from the checkbox element. Now, I need this function to be trigg ...

Creating a simple Node.js project using material web components - a step-by-step guide

I have recently started experimenting with Node.js. This is a basic program I created to test the integration of material-components-web. I followed the instructions provided in the readme file and here's what I have implemented so far: package.json ...

Managing a JSON request from an AJAX form using PHP - the ultimate guide!

I'm encountering some issues with my PHP handler. Here is the code snippet for my handler: <?php // Creating headers $headers = array( 'accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8&a ...

How to retrieve the column names of a table using Web SQL?

Working on extracting column lists from Web SQL (Chrome's local database). One approach is to gather information from sqlite_master. SELECT name, sql FROM sqlite_master WHERE type="table" AND name = "'+name+'"; As an example, here is a sam ...

Wondering how to optimize FullCalendar for mobile and touch events?

I am looking to incorporate a drop event feature into the mobile version of fullcalendar. To achieve this, I am utilizing Jquery UI Touch Punch. After researching on various platforms such as Stack Overflow 1, Stack Overflow 2, Stack Overflow 3, Stack Ove ...

Is it possible to iterate through an object with multiple parameters in Op.op sequelize?

Currently, I am in the process of setting up a search API that will be able to query for specific parameters such as id, type, originCity, destinationCity, departureDate, reason, accommodation, approvalStatus, and potentially more in the future. const opt ...

What is the best way to prevent code execution until a value is returned by $.get?

My attempt to read data from a file and store it in an array using jQuery's get function has hit a snag. Since the get function is asynchronous, the code that comes after the $.get call runs before the data is defined. How can I make sure that the cod ...

Using JavaScript to Retrieve URLs and Identify HTTP Status Code 403

In my JavaScript code, I am attempting to retrieve a 403 Forbidden response code using JavaScript. I have tried modifying the following code, but it does not seem to be working for me: <script type="text/javascript"> var request = new XMLHttpRequ ...

Guide for implementing smooth fade in and out effect for toggling text with button click

I have this code snippet that toggles text on button click: <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> function toggleText(){ ...