Struggle with Transmitting Information in Ionic 2

I have been working on an Ionic project that involves a JSON file with preloaded data. The initial page displays a list from which a user can select an item to view its content. However, I am encountering a "Response with status: 404 Not Found for URL" error.

Here is my provider code:

  // fetching names details
   getNamesDetails(title: string): Observable<Names[]> {
     return this.http.get(`${this.namesUrl}/{title}`)
        .map(
          (res) => <Names[]>res.json()
        )
   }

This is the class used to pass data to the next page using navParam:

  detailPage(title: string){
    this.navCtrl.push(NameDetails, {title});
  }

Below is the view for the second screen:

<ion-header>
  <ion-navbar color="primary">
    <ion-title>
      <!--Details-->
      {{ title }}
    </ion-title>
    <ion-buttons end>
      <button ion-button icon-only (click)="aboutUs()">
        <ion-icon ios="ios-options-outline" md="md-options"></ion-icon>
      </button>
    </ion-buttons>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <ion-card>
    <ion-card-header >
      <strong>{{title}}</strong> 
    </ion-card-header>
    <ion-card-content>
      {{text}}
      <p end><i>{{verse}}</i></p>
    </ion-card-content>
  </ion-card>
</ion-content>

The structure of my JSON files is as follows:

[
    {

        "title": "some title",
        "text": "some text",
        "verse": "some text"

    }
 ]

Answer №1

Through persistence and experimentation, I finally arrived at a solution.

Service Provider

   getNamesDetails(): Observable<Names[]> {
     return this.http.get(`${this.namesUrl}`)
        .map(
          (res) => <Names[]>res.json()
        )
   }

Function for transferring data to the subsequent page.

  detailPage(event, name: Names[]){
    console.log(name);
    this.navCtrl.push(NameDetails, {
      name: name
    })

  }

Display on the second page.

<ion-content padding>
  <ion-card >
    <ion-card-header >
      <strong>{{name.title}}</strong> 
    </ion-card-header>
    <ion-card-content>
      {{name.text}}
      <p item-right><em>{{name.verse}}</em></p>
    </ion-card-content>
  </ion-card>
</ion-content>

In the constructor of the second page class, I invoke the get method.

  constructor(public navCtrl: NavController,
              private http: Http, 
              private dataService: DataService,
              private navParams: NavParams) {
                this.name = this.navParams.get('name')
              }

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

Learn how to retrieve key and value data from a JSON file by utilizing the gson library

I am attempting to extract the key and value from a JSON string. Since I do not have prior knowledge of the key, I am unable to directly access the corresponding value using the key. Instead, I need to retrieve the key and value separately. JsonObject json ...

What is the best way to define types for an array of objects with interconnected properties?

I need to define a type for an object called root, which holds a nested array of objects called values. Each object in the array has properties named one (of any type) and all (an array of the same type as one). Below is my attempt at creating this type d ...

Encountering issue with POST operation in GraphQL on Angular application integrated with AWS Amplify and DynamoDB

I am in the process of developing a basic Angular application using AWS Amplify with a DynamoDB backend. To handle GraphQL API calls, I utilized the amplify add API command to generate the necessary code. My current objective is to populate a table with ...

"Error encountered: 'Callable function cannot be invoked on Mongoose model

In my Nest JS service, the code structure is as follows: import { Injectable } from '@nestjs/common'; import { Model } from 'mongoose'; import { InjectModel } from '@nestjs/mongoose'; import { Collection } from './inter ...

Puppeteer: implementing wait timeout is crucial to successfully handle Auth0 login process

Recently, I started using puppeteer and encountered some unexpected behavior. It seems that the waitForSelector function does not work properly unless I include a delay before it. Take a look at the following code: const browser = await puppeteer.l ...

Singleton Pattern in Angular Dependency Injection

In my code, I have a service called MyService that is decorated with the following: @Injectable({ providedIn: 'root' }) Part of its implementation includes: private myData: string = ''; setData(data: string) { this.myData = d ...

Is it possible to convert an adjacency list into JSON format?

Presented is an example of an adjacency list: A - A1 A - A2 A - A3 A3 - A31 A31 - A311 A31 - A312 The desired output format is as follows: { "name": "A", "children": [{ "name": "A1" }, { "name": "A2" }, { ...

Uncover the hidden message within the unique special character "ì"

My JSON file contains a specific character, such as ì; Here is the service I am using: $http({ url: jsonUrl, method: "GET" }).success(function (data) { // data is an array that contains a list of elements (f ...

The data type 'string' cannot be assigned to the data type 'Position'

Currently, I am in the process of converting React js to typescript. The component being used is a Class Component. I would like to obtain CSS settings through props and apply them to an element. How can I resolve this issue? render(){return( <span st ...

node.js + typescript How can we access instances from methods?

Following a server rebuild, the compiler creates an instance in the included API controller as shown below: NewController.ts import express = require("express"); import INew = require("../interface/INew"); import New ...

Having trouble getting material-ui container to work with custom breakpoints in TypeScript?

Currently, I am exploring material-ui and typescript within my educational project. However, I have encountered a perplexing issue for which I am seeking assistance. In this project, I utilize custom breakpoints in the material-ui theme settings. import { ...

Mismatched URLSearchParam type {property: value} does not match with undefined and Argument Type {property: value} cannot be assigned to {property: value}

Every time I try to run the code below, I encounter this error. The code is supposed to take a refresh token as input and make a POST request using URLSearchParams to a specific URL. However, I keep getting an error related to URLSearchParams. https://i.s ...

Unable to transfer variable from a function to the test in Protractor

Currently, I am working on a test to verify the amount of gold in my possession. The test is being conducted using TypeScript and Protractor. Within this testing scenario, I have a method named GetAmountOfChips: public static GetAmountOfChips(): PromiseL ...

Discover the method to determine the total count of days in a given week number

I am developing a gantt chart feature that allows users to select a start date and an end date. The gantt chart should display the week numbers in accordance with the ISO standard. However, I have encountered two situations where either the start week numb ...

Does the JSON property that exists escape NodeJS's watchful eye?

I recently encountered an unexpected issue with a piece of code that had been functioning flawlessly for weeks. In the request below and snippet of the response: //request let campaignRes = request('POST', reqUrl, campaignOptions); //response ...

Avoiding the occurrence of routing errors when an error arises in Angular 2

I've observed that whenever an error occurs in my Angular 2 application, it also disrupts the routing. Is there a method to address this and avoid the issue of breaking routing? ...

Clarifying the concept of invoking generic methods in TypeScript

I'm currently working on creating a versatile method that will execute a function on a list of instances: private exec<Method extends keyof Klass>( method: Method, ...params: Parameters<Klass[Method]> ) { th ...

Can someone please point me in the right direction to locate a Typescript project within Visual Studio

I've been struggling with this issue for days and still can't find a solution. After installing the Typescript tool for Visual Studio 2015, it appears to be successfully installed. https://i.stack.imgur.com/nlcyC.jpg However, I am unable to loc ...

HTTP request in Angular with specific body content and custom headers

My goal is to access the sample API request from , as demonstrated in the documentation: curl -H "api-key: 123ABC" \ -H "Content-Type: application/json" \ -X POST \ ...

Transforming a few lines of PHP header code to Classic ASP

I am encountering an issue with two files that I have: A locally hosted project coded in Ionic/AngularJS that is attempting to retrieve JSON data from an ASP file. An external ASP File which generates JSON data based on database values from a query. Eve ...