Discovering alterations in a component's attribute -Ang8

In my component, there are buttons to set the properties as follows:

dataType:String = null
 fechaI : Date = null
 fechaF :Date = null
 checkedList =[]

I need to trigger an HTTP request when all properties have values and redo the request if any of them change during runtime.

I attempted using ngDoCheck:

ngDoCheck(){
    if((this.checkedList !=null)&&(this.dataType!=null)&&(this.fechaI !=null)&&(this.fechaF !=null)){
      console.table(this.checkedList)
      console.log(this.dataType)
      console.log(this.fechaF)
      console.log('Sending Options')
      this.http.post('',{})
  }
}

However, the doCheck hook gets triggered every time I scroll or perform any action, making it not a suitable solution. How can I achieve the desired outcome?

Answer â„–1

If you want to monitor and react to changes in your controller variables, follow this approach:

An effective method for implementing change detection is consolidating your variables into a single object like so:

myData = {
  type: null
  startDate: null
  endDate: null
  selectedItems: []
}

In your view:

<input type="text"  
  [ngModel]="myData.type"
  (ngModelChange)="onUpdate($event)"
  name="type"
  required>

To detect changes:

onUpdate($changes) {
  console.log($changes)
  this.http.post(myUrl, $changes) // Placeholder
}

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 toISOString() method is deducting a day from the specified value

One date format in question is as follows: Tue Oct 20 2020 00:00:00 GMT+0100 (Central European Standard Time) After using the method myValue.toISOString();, the resulting date is: 2020-10-19T23:00:00.000Z This output shows a subtraction of one day from ...

Permitted the usage of a global variable of any type as the return value of a function that does not explicitly define its

Here's a snippet of TypeScript code that compiles successfully: let testVar: any; const testFunc: () => number = () => { return testVar; }; Why does this code compile without errors? What is the reasoning behind it? ...

The conditional expression is failing to function properly when applied to multiple form controls in the latest version of @rxweb/[email protected]

I am currently working on a form that includes various field validations based on a boolean variable called isNewCustomer. this.customerDetailsFormGroup = this._formBuilder.group({ customer: [this.order.customer_details.name, [RxwebValidators.r ...

Steps for calculating the average of several columns within a table using Angular 10

Currently, I have a function that successfully calculates the sum of JSON data in all columns on my tables. However, my attempt to get the average of each column is resulting in NaN or infinity. What could be the issue here? Here is my current implementat ...

using outlines for FontAwesome icons in React Native

I am struggling to use the fontAwesome + icon in the middle of a circle as one item. I have tried placing it inside a circle icon, but it doesn't seem to work properly. import IconFA from 'react-native-vector-icons/FontAwesome'; < ...

Angular MDBootstrap formatting disappears upon refresh of the page

I am currently utilizing the MDBootstrap package for Angular in my project, specifically focusing on styling buttons within a page I am developing. Upon initial loading of the page, the button styles are successfully applied. However, upon reloading the p ...

Employing multiple subscriptions within a function

I am facing an issue in my Angular application where I am trying to display a detailed summary of the sales for a specific drink using the DrinkDetailComponent. However, upon initializing the component, only one backend call is being made to retrieve infor ...

Utilizing class-validator for conditional validation failure

Implementing conditional validation in the class-validator library using the given example, I need to ensure that validation fails if the woodScrews property is assigned a value when the tool property is set to Tool.TapeMeasure. I've searched extensiv ...

Managing the ERR_NAME_NOT_RESOLVED issue

Currently, I am facing a task related to the health check endpoint where I need to receive a response from the backend or encounter a net::ERR_NAME_NOT_RESOLVED error if we are outside of a specific network. When attempting to send a request to my endpoin ...

Retrieving template variable within a directive's host listener function

Can 'habitCellInfo' be accessed from the template within the onvalueChanged host listener? <div *dxTemplate="let habitCellInfo of 'habitEditCellTemplate'"> <dx-select-box (onValueChanged)=" onHabitEdi ...

What is the best way to add a 'Drawer' component into the 'AppBar' using React MUI within the Next.js framework?

My goal is to create an App bar with a 'hamburger' icon on the left that, when clicked, will display a Sidenav (drawer). I am working with React Material and Next.js (App router) and need to have the app bar and drawer as separate components, hea ...

Unable to delete event listeners from the browser's Document Object Model

Issue at hand involves two methods; one for initializing event listeners and the other for deleting them. Upon deletion, successful messages in the console confirm removal from the component's listener array. However, post-deletion, interactions with ...

What could be causing my website to lose its responsiveness after linking a domain?

Recently, I created a basic website for an event in my town using AWS Amplify from Amazon. Initially, the website was hosted without a custom domain and had a random URL. It worked well on both web and mobile platforms. However, after connecting a custom d ...

Mapping data arrays for a particular type of object array

Perhaps a simple query, but I am struggling to find an example for this. Here is my HttpClient call: getItems(dataSourceUrl: string, bindKey: string, bindValue: string): Observable<SelectItem[]> { return this.httpClient.get<Array<any>& ...

Guide to crafting a reply using nestjs exception filters with nestfastify

I'm facing a challenge with writing custom HTTP responses from NestJS exception filters. Currently, I am using the Nest Fastify framework instead of Express. I have created custom exception filters to handle UserNotFoundException in the following mann ...

Choose the initial selection from a list of changing values using Ionic

I'm having trouble selecting the first option in an Ionic select. I've written a condition based on indexes where if the index is 0, checked should be true, but it's still not working. Here is my code: <ion-item> <ion-l ...

Using Angular 2: Pass the field of each item in *ngFor as a parameter when calling a function

I have a functional management application that displays a list of services along with some information (developed last year). Now, I want to add the functionality to show "last request" information on click. However, I encountered an issue with the code i ...

Is it possible to build a Node.js (Express) application using a combination of JavaScript and TypeScript?

Currently, I have a Node.js project (Express REST API) that is written in JavaScript. My team and I have made the decision to gradually rewrite the entire project into TypeScript. Is it possible to do this incrementally, part by part, while still being ab ...

Most effective methods for validating API data

Currently, I am working on developing an api using nestjs. However, I am facing some confusion when it comes to data validation due to the plethora of options available. For instance, should I validate data at the route level using schema validation (like ...

How to fix the TS4090 error regarding conflicting definitions for a node in Visual Studio 2017

My TypeScript project is building and running, but I'm encountering a multitude of build errors all originating from one issue: TS4090: (TS) Conflicting definitions for 'node' found at 'C:/[projectpath]/node_modules/@types/node/index ...