A guide to updating a table in Angular using an API response

My form allows me to select events from a drop-down list and choose a date. Depending on the selected date, it retrieves the number of events that occurred on that specific date. If I select an event and a date where events took place, the "All Events" section displays a list of those events. However, if I change the date to one where no events occurred, the "All Events" section does not update and continues to show the previous value fetched from the API. How can I refresh the data in HTML based on the API response?

component.html code

          <form [formGroup]="viewForm" (ngSubmit)="infoSubmit(viewForm.value)">
      <div class="form-group row">
        <div class="col-md-6 txt-box">
          <select type="number" class="form-control" 
     formControlName="Name">
            <option value="">Events</option>
            <option *ngFor="let Name of listOfEvents"
              type="number" [ngValue]="Name.Id" >
              {{ Name.Name }}
            </option>
          </select>
        </div>
      </div>
      <div class="form-group row">
        <div class="col-md-12 txt-box">
          <div class="dateTime row">
            <div class="col-md-3 txt-box">
              <input formControlName="dateStart" [owlDateTime]="dt1"                   
              placeholder="Start Date"/>
              <span [owlDateTimeTrigger]="dt1"><i class="fa fa-calendar"></i></span>
              <owl-date-time [showSecondsTimer]="true" #dt1></owl-date-time>
               </div>
              </div>
        </div>
      </div>
      <button class="a-btns btn btn-success tab-btn"  type="submit" >
        Submit
      </button>
           <div class="row">
               <table class="table tabs links">
              <thead>
                <tr>
                  <th>All Events</th>
                 </tr>
              </thead>
              <tbody>
                <tr *ngFor="let file of AllEventList"> </tr>
              </tbody>
            </table>
          </div>
           </form>

component.ts code

      logInfoSubmit(v) {   
   const Id = v.Name;   
if (this.viewForm.valid) {
const dateTime = this.viewForm.value;
let startTimeDate = dateTime.dateStart.toISOString();
const Info = {
  PathDirectory: this.tempLog,
  StartDate: startTimeDate     
};    
this.service.getView(Id,Info).subscribe((res: any) => {
 
  if(res.payload == ''){
   
    this.toastrService.info(res.message);
  }
  else{
    this.AllFileList = res.payload;

    this.toastrService.info(res.message);
  }
  });
 } 
 }

Answer №1

In my opinion, it appears that you are only requesting events from your service once.

You can solve this by adding an onClick property to the submit button and triggering another call to your service with the updated start date.

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

I have encountered the same installation error with every Angular Masonry package I have tried to install on various applications

Every time I try to install one of the popular masonry packages for Angular, I encounter the same frustrating error. It's getting to the point where I feel like pulling my hair out. Unexpected token d in JSON at position 702 while parsing near ' ...

"Maximizing Bootstrap Functionality with Angular 2: Step-by

I'm experiencing an issue with Angular2, Bootstrap 3.3.7, and Bootstrap Plugins. I have imported all the necessary stylesheets and JavaScript files in the 'index.html' file. Below is the snippet from the index.html: <!-- Bootstrap & ...

Ways to access a property within an object using TypeScript

Can you help me extract the "attributes" array from this object and store it in a new variable? obj = { "_id": "5bf7e1be80c05307d06423c2", "agentId": "awais", "attributes": [ // that array. { "created ...

Expanding the Element prototype with TypeScript

Is there a corresponding TypeScript code to achieve the same functionality as the provided JavaScript snippet below? I am looking to extend the prototype of the HTML DOM element, but I'm struggling to write TypeScript code that accomplishes this with ...

Determine an expression based on a string in Typescript

Looking at the code snippet below, everything appears to be in order (view playground): type PathParam<T> = T extends `${string}:${infer U}` ? U : never; type Param = PathParam<"/post/:post_id">; // type Param = "post_id" ...

Creating a custom data type using values from a plain object: A step-by-step guide

I recently came across an object that looks like this: const myObject = { 0: 'FIRST', 10: 'SECOND', 20: 'THIRD', } My goal is to define a type using the values from this object, similar to this: type AwesomeType = &apos ...

Customizable parameters in a React component

I am encountering two issues with the code provided below: interface MyForm { age: number; email: string; name: string; } function Form< T, ComponentProps extends { name: string; onChange: (event: React.ChangeEvent) => void; } &g ...

An error occurred when attempting to access data within a variable that is undefined, resulting in a TypeError at the errorHandler function

Every time I attempt to send a post, patch, or put request, I keep getting this error. However, there are no issues with get requests. TypeError: Cannot read properties of undefined (reading 'data') at errorHandler (/home/joe/Documents/mypro ...

Building an advanced numerical input validation system with Angular 7

In AngularJS, the following code is used to create a form with an input field of type "number": <form name="f" novalidate> <input type="number" ng-model="x" name="x"> </form> <div ng-if="f.x.$error.number">NaN</div> Is it p ...

Completing a fetch promise and sending the outcome to a function that is not awaited

I have a function that retrieves data from a Postgresql database and returns it. The expected behavior is to fetch the data using the async function getCat(), process it in const Catalogue, and then return it to a ReactJS component. catalogue.tsx: import ...

Error TS2339: Cannot access attribute 'reactive_support' on interface 'LocalizedStringsMethods'

Encountering the error TS2339: Property 'reactive_support' does not exist on type 'LocalizedStringsMethods' I recently updated TypeScript from version 2.6 to 2.9, and attempted import LocalizedStrings from 'react-localization&apo ...

Error: Cannot modify the constant property 'name' of the function."&squo;

As I attempted to enter text into the input box, an error message appeared after typing my first letter stating "cannot assign to read only property". Below is the code I am referring to: The code of the component can be found here: This is the specifie ...

Accessing Webpack bundles using an "@" symbol for imports

I am currently working on bundling a Node Express server that was created using TypeScript and is being packaged with Webpack. Everything seems to be running smoothly when I compile/transpile the code into one JavaScript file called server.js. However, af ...

Creating an OpenLayers map within an Ionic component

Implementing Ionic v4 with OpenLayers v5.3 I am facing an issue while trying to display an OL map as a component in my project. Only the icons are being loaded and it seems like the styles and JS configuration are not loading properly. I have tried inject ...

Top choice for removing items from a list array

Hey there, I'm working with an array of a custom type in Angular: List { task: string; id?: number; status?: boolean; } I'm trying to figure out how to delete elements where List.status == true. I've tried two methods for this. ...

Displaying a segment of information extracted from a JSON array

I'm currently tackling a project that involves using React, Redux, and TypeScript. Within the JSON file, there is a key-value pair: "data_start": "2022-09-02" Is there a way to display this date in a different format, specifical ...

Creating a conditional property in TypeScript based on an existing type - a comprehensive guide

Imagine if I had the following: type Link = { text: string; link: string; } interface BigLink extends Link { some: number; something: string; else: string; } However, there's a variable that shares all these properties except for the fact ...

Transferring form state information between parent and child elements

In my development project using Angular 2, I encountered an issue with managing a long and complex form by splitting it into a parent component and two child components for better organization. The challenge arose when I needed to track the form status for ...

What is the process for enabling keyboard selections in a Material-UI Select component?

Is there a way to make the MUI Select component keyboard accessible by tabbing into it and using the first letter of the option to auto-select without opening the list? I am looking for a feature where pressing the initial letter selects the first item tha ...

Extract from Document File

After receiving a PDF through an Angular Http request from an external API with Content Type: application/pdf, I need to convert it into a Blob object. However, the conventional methods like let blobFile = new Blob(result) or let blobFile = new Blob([resul ...