Guidance on navigating to a different page using a specific identifier

I'm a beginner in Angular, currently working on developing a full stack MEAN application. I need some guidance regarding an issue I'm encountering. My goal is to create a form called 'fa-daform.component.html' that captures a brief description, author, and date which will be stored in a database with a randomly generated ID. Upon clicking the submit or create form button, I want the user to be redirected to a new page, 'detailed-daform.component.html,' where they can fill out a more detailed form using the ID of the previously entered data for reference.

Here is the HTML code for the Brief Description file (fa-daform.component.html):

<div>
    <mat-toolbar class="menu" color="primary">
        
        <div class="centerNavBar">
            <a mat-button href="fa-dashboard">Back</a>
             
            <span class="headSpacer">Damage Assessment Tool</span>        
             
            <a mat-button href="">Logout</a>
        </div>
    </mat-toolbar>
</div>

... // Truncated for brevity

In the TypeScript file for the Brief Description form (fa-daform.component.ts), I have defined functions for creating a new Damage Assessment Report:

import { Component, OnInit } from '@angular/core';
import { DamageAssessmentReportService } from 'src/app/damage-assessment-report.service';

@Component({
  selector: 'app-fa-daform',
  templateUrl: './fa-daform.component.html',
  styleUrls: ['./fa-daform.component.css']
})
export class FADAFormComponent implements OnInit {

... // Truncated for brevity

The Detailed Form file (detailed-daform.component.html) simply contains a message indicating its functionality:

<p>detailed-daform works!</p>

If you encounter the error "Property 'detailedDAFormID' does not exist on type 'FADAFormComponent'," you can refer to my project's GitHub repository at [https://github.com/DillonRampersad/Damage_Assessment_Tool]. Feel free to explore activated routes for resolving this issue. Your assistance in this matter would be greatly appreciated.

Answer №1

Consider utilizing the Router

 <button mat-raised-button type="submit" 
  (click)="createDamageAssessmentReport(DescOfReportInput.value, AuthorInput.value, DateInput.value)"  color="primary" >Create</button> 

In a nutshell, in the typescript file named fa-daform.component.ts:

import { Component, OnInit } from '@angular/core';
import { DamageAssessmentReportService } from 'src/app/damage-assessment-report.service';
import { Router } from '@angular/router';

@Component({
  selector: 'app-fa-daform',
  templateUrl: './fa-daform.component.html',
  styleUrls: ['./fa-daform.component.css']
})
export class FADAFormComponent implements OnInit {


  constructor(private damageAssessmentReportService : DamageAssessmentReportService, private router: Router) { }
  
  //assessmentDescription: string, author: string, reportDateTime: Date
  createNewDAReport(){
    this.damageAssessmentReportService.createDAReport("New Report","Dillon", new Date(2020, 9, 10)).subscribe((response : any)=>{
      console.log(response);

    })
  }

  createDamageAssessmentReport(assessmentDescription: string, author: string, reportDateString: string){

    const reportDateTime = new Date(reportDateString); // Here you should have your date ready to be used as you wish
    this.damageAssessmentReportService.createDAReport(assessmentDescription,author, reportDateTime).subscribe((damageAssessments : any)=>{
      console.log(damageAssessments);
      //navigate to /damageAssessments/damageAssessments._id
      this.router.navigateByUrl(`damageAssessments/${damageAssessments._id}`)
  })
  }

  
  ngOnInit(): void {
  }

  }

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

Creating dynamic routes with Nuxt3

Within my nuxt.config.ts file, I have the ability to generate multiple routes using the following code: export default defineNuxtConfig({ generate: { routes: ['/products/1', '/products/2'] }, }) After running nuxt generate, thi ...

What is the best method for saving information from a service to a class or interface in Angular 2?

I am currently in the process of developing a new web application and I am fairly inexperienced with Angular2. I am encountering an issue with one of my components that acts as a form for users to update their data. The problem lies in accessing specific ...

NextJS 12: The dilemma of styled components not rendering server side due to missing CSS

Exciting news with the latest NextJS 12 release - now styled-components is supported without the need for any extra plugins on NextJS! However, I'm running into issues getting it to work with server-side rendering. To activate it, I installed the sty ...

A script to continuously execute a form action in a loop

As someone transitioning from software development to web development, I find the study of web development quite confusing. Please bear with me as I ask this newbie question. My goal is to test every domain within my array (dMains) so that each domain can ...

What method can be used to ensure Moment.js gives priority to the day over the month when interpreting dates with ambiguity

Is there a way to set Moment.js to default to assuming that the day comes before the month in ambiguous situations? For instance: moment("10-05-2018") would interpret as 10 May 2018 moment("06/08/2018") would be assumed as 06 August 2018 moment("01 03 ...

I'm wondering if it's possible to fork an npm library in package.json and automatically trigger its build process upon installation

I am currently facing an issue with a npm dependency, such as ngx-infinite-scroll, that I am trying to fork for bug fixes. I want to include my modified version as a dependency in my application. Here is an example of how I have included it in my package.j ...

Youngster listens for guardian's occurrence in Angular 2

While the Angular documentation covers how to listen for child events from parents, my situation is actually the opposite. In my application, I have an 'admin.component' that serves as the layout view for the admin page, including elements such a ...

Trapping an iframe refresh event using jQuery

I am trying to dynamically load an iframe using jQuery. Here is my code: jQuery('<iframe id="myFrame" src="iframesrc.php"></iframe>').load(function(){ // do something when loaded }).prependTo("#myDiv"); Now, I need to capture th ...

Typescript interface requiring both properties or none at all

I possess key-value pairs that must always be presented together in a set. Essentially, if I have one key with its value A:B, then there should also be another key with its value C:D. It is permissible for the object to contain neither pair as well. (An ex ...

Angular2 encountered an error loading the resource: server reported status 404 (Not Found)

I am currently using Angular2 with Visual Studio 2015. I tried to follow the instructions from Hello World! in Angular 2 using Visual Studio 2015 and ASP.NET 4, but encountered an error. Error Message Error: (SystemJS) XHR error (404 Not Found) loading ...

Browser Integration for Real-Time Updates on GetStream io Platform

Integrating getstream.io into our framework has been a challenge. We aim to deliver activities to subscribers and provide clients with the ability to filter these activities. Unfortunately, GetStream does not support filtering on activities directly, so I ...

My redirect is being disrupted by passing a text string with new lines through GET requests

My issue involves submitting a form that utilizes JavaScript to pass a value through GET. Upon reaching the submission page, the function runs successfully, but when redirecting via the header, it ends up on a blank page. The header code for redirection lo ...

Discovering ways to retrieve the complete HTTP response in Angular to access certain response headers

In my angular app, I need to check for specific response headers to handle JWT validation. If a user tries to access a route that requires a valid JWT with an expired token, the back-end ASP.NET Core server will have a response header token-expired: true. ...

Tips for incorporating a Survey Monkey website embed into an Angular application

I have a Survey Monkey account with multiple surveys. I am trying to embed a survey from this website into my Angular website, which already has Bootstrap and jQuery added. I attempted to directly add the script in an HTML component, but it did not work. ...

The axios requests are sent to the backend API, but the webpage remains empty without

I am trying to retrieve a base64 encoded image from my local backend by making a local API call. The logging on the backend confirms that axios is successfully calling the API, however, the frontend displays an empty page with no data. What could be caus ...

Troubleshooting Highcharts container selection problem on Nexus 7 running version 4.2.1

Having a problem with Highcharts on my Nexus 7. When I touch the chart, the entire thing gets selected with a blue overlay, but this doesn't happen on other devices like the Nexus 4. Even when I try accessing demos from Highcharts website, the issue ...

Revise the JSON format to be compatible with a JavaScript template library

My goal is to utilize JSON data for parsing a template using JavaScript. The Mustache library provides a solution as shown below: var output = $("#output"); // template stored in JS var as a string var templateString = '<div>'+ '< ...

Updating *ngIf in Angular 6 after the Component has finished Loading

Component: import { Component, OnInit } from '@angular/core'; // Services import { AuthService } from './services/auth.service'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleU ...

AngularJS basic webpage application halts code rendering

While working on an AngularJS tutorial on codeschool.com, I encountered a frustrating issue. Every time I refresh my browser to check my progress, the webpage ends up blank and refuses to load the code. I've restarted the tutorial from scratch twice, ...

When making an AJAX request, ensure the response is in JSON format with individual properties rather than as a single

Here's an example of an AJAX request with JSON dataType: JavaScript: function checkForNewPosts() { var lastCustomerNewsID = <?php echo $customers_news[0]['id']; ?>; $.ajax({ url: "https://www.example.com/check_for_n ...