Navigating to a property List to then view a property Detail page and showcase the specific details of the selected property, encountering a 404

Using the httpClient to fetch data from a local json file, everything operates smoothly in the propertylist. However, when selecting a property and wanting to show its details on a new page, I'm struggling to grasp the concept despite watching numerous tutorials and reading guides.

It appears that the issue lies within routing, activated route, and parameters. I've set up the pages, service, imported router and activatedrouter, injected my service, and configured the :id path in the routing module.

Snippet of JSON Data

{
    "property": [
        {
            "propertyID": "101552000007",
            "branchID": "1",
            "clientName": "Demo",
            "branchName": "Br",
            "department": "Sales",
            "referenceNumber": "10006",
            "addressName": "",
            "addressNumber": "87",
            "addressStreet": "Hackney Road",
            "address2": "",
            "address3": "London",
            "address4": "",
            "addressPostcode": "E2 8PP",
            "country": "United Kingdom",
        }
    ]        

For-Sale Page

<ion-col *ngFor="let property of propertyList.property; let i=index" size="6">


<ion-card  [routerLink]="['/read-post',property.propertyID]">

Service Configuration

getProperty(propertyID): Observable<IProperties[]> {
        return this.http.get<IProperties[]>('/assets/data/xx.json/' + propertyID);
}

Read-Post Page Initialization

    ngOnInit() {
        let propertyID = this.route.snapshot.params['id'];
        this.saleService.getProperty(propertyID).subscribe((property) => {
            console.log(property);
        });
    }

App-Routing Configuration

{ path: 'read-post/:id', loadChildren: './read-post/read-post.module#ReadPostPageModule' },

Upon clicking a property on the for-sale page, it should navigate to "http://localhost:8100/read-post/101552000015" (the propertyID in the json)

Console Output

GET http://localhost:8100/assets/data/xx.json/101552000015 404 (Not Found)

Answer №1

When handling the json file, it is essential to read the file instead of passing parameters to it directly. By reading the file first, you can then filter the data to extract the necessary property.

Take a look at the code snippet below which corresponds to the JSON data provided in your question.

To make adjustments, modify the getProperty() and ngOnInit() methods as shown:


    getProperty(): Observable<IProperties[]> {
            return this.http.get<IProperties[]>('/assets/data/xx.json/');
    }


    ngOnInit() {
            let propertyID = this.route.snapshot.params['id'];
            this.saleService.getProperty().subscribe( data => {
                if(Boolean(data) && Boolean(data.property)){
                    let requiredValue = data.property.filter(ele => ele.propertyID === propertyID)[0];
                    console.log(requiredValue);
                }
            });
    }

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

Angular 2, using Jasmine and Karma for testing, encountered an error with the HTTP testing API, which returned an error message stating: {"isTr

I've set up an http test case for my Angular2 app using Jasmine-Karma and encountered an API error: Uncaught API Error. Scenario: I'm trying to test an http service for my Angular2 App using Karma-Jasmine, and I've implemented the method be ...

What is the best way to share your NodeJS library, which is coded in TypeScript, to be compatible with both BrowserJS and NodeJS, while also taking advantage of

Similar to lodash, the library @yamato-daiwa/es-extensions offers common functions for both BrowserJS and NodeJS. However, unlike lodash, it has a single main file index.js with re-exports. Requirements This library: Must be compatible with browser envir ...

Trouble with loading TypeScript Express REST API routes!

I've been working on accessing data from my custom REST API, but I'm encountering an issue where the JSON data is not being displayed when I navigate to the endpoints. I have set up server, controller, and data controller classes in order to crea ...

Is it possible to leverage ES6 modules within a Node.js application while also debugging it using Visual Studio?

Trying to create a basic node.js module test project using ES6 in Visual Studio 2015 has resulted in build errors, preventing me from running or debugging the application. Could it be that I arrived at the party too soon? I attempted opening and building ...

What is the best way to update a page and retrieve fresh data from a service in Angular?

On my webpage, there is a table and two charts coming from three different controllers. I am looking for a way to refresh all of them simultaneously by clicking on a single refresh button. This will allow the data to be fetched from the webservice again an ...

Jest encountered an error while attempting to parse the TypeScript configuration file

I've been working on setting up Jest with Babel and Typescript, following the guidelines provided here. However, when I run npm run test, I encounter the error message: Error: Jest: Failed to parse the TypeScript config file C:...jest.config.js` Th ...

Can the inclusion of a type guard function impact the overall performance of the application?

const typeGuard = (param: any): param is SomeType => { return ( !!param && typeof param === "object" && param.someProperty1 !== null && param.someProperty2 === null ) } If a type guard function similar to the code above is exe ...

Sign up for notifications using NGRX

How can I incorporate CompanyEffects in my AppModule after receiving a response from the AppConfigService on the server? Effect registration within AppModule EffectsModule.forRoot([CompanyEffects]), CompanyEffects Implementation export class CompanyEff ...

Is it possible for Angular 2 JWT to have an unauthenticatedRedirector feature?

Having transitioned from Angular 1 where JWT tokens were used for user authentication, I had the following code: .config(function Config($httpProvider, jwtOptionsProvider) { // Interceptor to add token to every $http request jwtOptionsProv ...

What is the best way to deploy static Angular builds for microservices on AWS S3 and ensure proper routing management?

Our Company's SAAS platform currently utilizes 7 to 10 Angular microservices, previously hosted on an EC2 engine with routing managed by Nginx. However, due to high costs associated with EC2, I have successfully migrated the website to a static websit ...

When selecting an option, the radio button becomes unresponsive and locked in

Currently, I am tackling an Angular project and have created an application that must be compatible with iPad. The issue lies with the radio button - whenever it is clicked, it freezes/disables in Safari but works perfectly fine in other browsers like Ch ...

Validation for Zod does not appear to be activating when necessary input is missing

Can someone help me figure out why the validation in my Zod schema for a string input is not working as expected? Here's what I have: const nameSchema = z.string({ required_error: "Name is required", invalid_type_error: "Name ...

Guide to setting up a step progress bar in Angular 2 and beyond

https://i.sstatic.net/urCCV.png https://i.sstatic.net/l0XgJ.png https://i.sstatic.net/MjuOf.png I'm looking to create a 7-step progress bar in Angular2+ using TypeScript, SCSS, and HTML, similar to the image above. I'm unsure of how to proceed ...

pattern matching to establish the path for unit test files

Just starting to dive into regular expressions and I've encountered a situation in my test case config file where I need to specify certain files. var webpackConfig = require('./webpack.store1.config.js'); module.exports = function(con ...

Tips for solving the error "Angular CLI version 7.0.3 cannot install node-sass"

Every time I attempt to run npm start, an error message stating that it cannot find the module node-sass appears. Then, when I try running npm install node-sass --save, a series of errors pop up. https://i.stack.imgur.com/2I7DU.png ...

Despite having the same versions for Angular and Angular CLI, the build process using 'ng build'

After running ng v, the output shows: Angular CLI: 9.1.13 Node: 12.22.12 OS: win32 x64 Angular: 9.1.13 Strangely, attempting to execute ng build resulted in the following error: This version of CLI is only compatible with Angular versions ^13.0.0 || ^13. ...

Effective Approach to Implement Validation in Dynamic Display Column

I have a <mat-select> element in my Angular 7 project with an ngFor loop that displays rows from a table. I need to implement validation for the "type" column, allowing only one key to be selected at a time and preventing users from selecting "key" m ...

Having difficulty showing the ionic back button within my side menu

I recently added an ion-nav-back-button to my side menu in the ion-nav-bar, but I encountered an issue where the nav back button did not display. Despite trying various attributes, the button remains hidden. Below is the code for my menu layout with the si ...

The type definition file for 'bson' could not be located. It appears to be missing from the program due to being the entry point for the implicit type library 'bson'

I recently set up a new Typescript/React project and encountered the following error in the tsconfig.json file: "Cannot find type definition file for 'bson'. The file is in the program because: Entry point for implicit type library 'bson&ap ...

Aframe's a-assets feature experiencing issues when loading dynamic data through Angular 2

Since there is no fixed number of assets that need to be loaded from the server, I am utilizing Angular 2 templates to dynamically create assets. Below is a snippet of sample code: <a-assets> <div *ngFor="let scene of floorData.scen ...