No Data Being Displayed on Detail Page in Ionic

As a newcomer to Ionic, I am encountering an issue with my list code. The list is functioning properly, but when I click on a list item, it does not display any data. Instead, I receive the error message "Cannot GET /pilliondetails/1". How can I resolve this?

app.factory('myService', function() {
var savedData = {}
function set(data) {
savedData = data;
console.log(savedData);
}
function get() {
return savedData;
}

return {
set: set,
get: get
}
})

PillionList Controller:

.controller('PillionListCtrl',function($scope,$ionicHistory,myService){
$scope.myGoBack = function() {
$ionicHistory.goBack();
};

$scope.pillions = [];
var promise=myService.get();
$scope.pillions=myService.get();
})

PillionDetail Controller:

.controller('PillionDetailCtrl',function($scope, $ionicHistory, $stateParams, myService)
{
$scope.myGoBack = function() {
$ionicHistory.goBack();
};
var promise=myService.get($stateParams.requestId);
console.log(promise);
})

PillionList.html :Showing list pf Pillions

   <ion-list>
   <ion-item data-ng-repeat="pillion in pillions">
    <div class="list list-inset">
    {{pillion.request_departure_date}}-{{pillion.request_departure_time}}
    {{pillion.request_from}}&nbsp;&nbsp;>>&nbsp;&nbsp;{{pillion.request_to}}
    {{pillion.user_first_name}}&nbsp;{{pillion.user_last_name}}
    <a ui-sref="pilliondetails({pillionId:pillion.request_id})" nav-direction="enter">
        <h2>More Details...</h2>
    </a>
    </div>
    </ion-item>
   </ion-list>

my app.js

 .state('pillionlist', {
            url: '/pillionlist',
            templateUrl: 'templates/pillionlist.html',
            controller: 'PillionListCtrl'
        })

        .state('pilliondetails', {
            url: '/pillionlist/:pillionId',
            templateUrl: 'templates/pilliondetails.html',
            controller: 'PillionDetailCtrl'
        })

Although it redirects to the pillionDetail view, it fails to display any data. Any assistance would be greatly appreciated.

Answer №1

One of the first things that caught my eye was

ui-sref="pilliondetails({pillion.request_id})"

it needs to be structured as a key-value pair like this

ui-sref="pilliondetails({ your_id : pillion.request_id})"

and in the stateProvider, the URL for the details page should include a parameter. For example,

url : '/pilliondetails/:your_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

The onbeforeunload event is activated in the parent page when it is specified in the child page

Seeking a way to activate the window.onbeforeunload method when a user attempts to refresh the browser, and display a message to prompt them to save their current work before leaving. I am currently working on an AngularJS application. Here is the URL of m ...

Attempting to assign a class name to the <a> tag proves challenging as it seems to reset upon clicking the link, causing the class to vanish

Looking at this HTML code snippet <li> <a href="javascript:;"><i class="sidebar-item-icon ti-hummer"></i> <span class="nav-label">Product Management</span><i class="fa fa-angle-left arrow"></i>&l ...

Displaying a loading indicator as content loads within the iframe

How to Display a Loading Indicator During Content Loading Within an iFrame: 1) When a postback or submit event occurs within a form inside the iFrame ...

Create the transformation matrix for the Autodesk model

Can someone provide information about the following two matrices and their purposes? placementTransform (1 x 12) refPointTransform (1 x 16) I believe they may be related to translating (Tx, Ty, Tz) or rotating (Rx, Ry, Rz) 3D objects, but I am unsure du ...

Is there a way to prevent a background video from automatically playing whenever the user navigates back to the home page?

Recently, I was given a design that requires a background video to load on the home page. Although I understand that this goes against best practices, the client has approved the design and now I need to come up with a solution. The video is already in pla ...

Step-by-step guide on populating a state using an array

I am having trouble populating a list within a state using the set method, as the state remains empty App.js // Initiates the secrets word game const startGame = () => { // pick word and pick category const { word, category } = pickWordAndCat ...

What are your thoughts on combining a JSON object with HTML?

When using ASP.NET MVC, it is possible to return a JSONResult. return JSON(new { View = RenderViewAsString("MyView", model), wasSuccessful = true}) This approach combines HTML and data in a single JSON object. The goal is to utilize strongly typed HtmlHe ...

Looking for a modular approach? Incorporate specific parts of a module into the parent component

Developing a node.js module and aiming to organize my code effectively. My goal is to have individual files/folders for different parts of the module such as authentication, users, etc. These will be required from a parent package which will then expose t ...

Error occurred: Undefined module imported

CounterDisplay.js import React from 'react'; const CounterDisplay = <div> <h1>{this.state.counter}</h1> <button onClick={this.handleDecrement}>-</button> <button onClick={this.handleIncrement}>+ ...

Paging in Ext JS does not function properly when using local data sources

I am facing an issue with enabling paging in ExtJs4 grid. The paging toolbar appears to be functioning correctly, however, the paging feature does not seem to work within the grid itself. Can anyone provide guidance on what might be missing? Ext.onReady(f ...

Using npm scripts in JavaScript: A comprehensive guide

Could someone provide me with a comprehensive guide or reliable reference material on how to execute running module commands within a JavaScript file? For example, I frequently use the following command: $ npm run webpack-dev-server --progress --colors - ...

Get your hands on the PDF file with Angular!

Having an issue with downloading a PDF from a WebApi using Angular. The downloaded file is only 15 bytes, even though the data being received from the WebApi appears to be of the correct size when logged as an arraybuffer. The WebApi [HttpGet] pu ...

Having trouble retrieving the complete base64 encoded data through ajax

I am facing an issue with converting an audio blob to base64 and passing it through ajax to a php page for storage in an SQL server. However, the full base64 file is not being received in the MySQL database for some reason. Below is the code I am using to ...

Error in AngularJS: $injector:unpr Provider Not Found

I am currently in the process of creating my own service using the factory methodology as outlined in the documentation. However, I seem to be encountering an issue with an unknown provider error. Below is the code for my app which includes the declaration ...

Post with rectangular shape

In my current project, I am utilizing a RESTful API to store task-related JSON data. The backend is powered by Flask, while the frontend makes use of AngularJS. Currently, the system allows me to view all tasks. However, I am looking to convert this funct ...

What is preventing jQuery UI from detecting jQuery?

I have successfully created a JavaScript widget that is capable of being embedded on any third-party website, in any environment. The widget relies on jQuery and jQuery UI for its functionality. After following the guidelines outlined in How to embed Javas ...

Implement code to execute exclusively on the initial success of react-query

I have a unique scenario where I need to utilize standard useQuery behavior, while also executing a piece of code only on the initial onSuccess event. Although I understand that I can accomplish this using useRef, I am curious if there is an alternative a ...

Exploring Various JSON Arrays

There are 3 arrays provided below which I have no control over: groups_array = [ { "group" : "Mobile Test Region", "id" : "251" }, { "group" : "Mobile Demo Region", "id" : "252" } ] locations_array = [ { "location" : "M Testing", " ...

Verify the presence of a specific value within an array of objects in JavaScript that was retrieved from an AJAX response, and then

I am encountering an issue with the code below where I am unable to filter entry.AllLinks. The code snippet is shown here: $.ajax({ url: url, type: "get", headers: {"Accept": "application/json;odata=verbose"}, success: function (data) { ...

Exploring modifications in axis for Google charts timeline

Can anyone help me figure out how to set my Google Timeline chart to always display 24 hours on the x-axis? Currently, it automatically changes based on the earliest and latest points, but I want it to consistently show all 24 hours. For example: ...