Executing a function prior to signing up

Is there a way to dynamically add a form control once the user has made a selection?

This is my select function:

selected(event: MatAutocompleteSelectedEvent): void {
      this.setTechnologies = new Set();
      this.setTechnologies.add(this.techInput.nativeElement.value);
}

Integrating a new controller

this.primaryFormGroup.addControl('tech', new FormControl('', []));
this.primaryFormGroup.valueChanges.subscribe(inputFields => {
  if (inputFields) {
    inputFields.tech = Array.from(this.setTechnologies);
  }
}

The issue I'm facing is that the line

inputFields.tech = Array.from(this.setTechnologies);
gets executed, prior to the execution of the selected() function. Consequently, the value of inputFields.tech always remains empty.

How can I ensure that the function runs first?

Answer №1

To enhance the performance, one tactic is to introduce a minor delay in the execution of valueChanges. By doing so, it guarantees that the selected() function takes place prior to valueChanges.

this.primaryFormGroup.valueChanges.pipe(
  delay(500)
).subscribe(inputFields => {
  if (inputFields) {
    inputFields.tech = Array.from(this.setTechnologies);
  }
}

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

Utilizing GUID model binding within ASP.NET MVC

Can someone please assist me in resolving this issue? I've been struggling to find the solution and it seems like there's something obvious that I'm missing... The problem I am facing involves sending a GET request from my JavaScript code, ...

Troubleshooting error in WordPress: Changing innerHTML of dynamically created divs using JavaScript. Issue: 'Unable to set property innerHTMl of null'

I am struggling to modify the innerHTML of a "View cart" button using a dynamically generated div class on my Wordpress/Woocommerce site. In a previous inquiry, I was informed (thanks to Mike :) ) that since JavaScript is an onload event, the class changes ...

Methods for invoking a function from a separate .js file within React Native Expo

I'm new to using React and I've come across a challenge: In my Main.js file, there is a button: import * as React from 'react'; import { StyleSheet, Text, View, SafeAreaView, Pressable, Alert } from 'react-native'; import { M ...

Having trouble with the copy to clipboard function of Prism JS on my NextJs application

I am facing an issue while trying to integrate a copy to clipboard plugin from prismjs into my next.js app. I have searched for documentation on this but couldn't find any relevant information. Despite going through various websites and implementing t ...

Font transparency is not displaying properly

I am attempting to adjust the opacity of text displayed on a d3 pie chart, but I'm facing issues where only the fill is rendering correctly and not the opacity. Below is the code snippet where I am trying to apply opacity: var txts = svg.data([json ...

Utilize graphics in three.js for texture recycling

My challenge involves loading the same image in a large number (~ 1000) of two-dimensional shapes using three.js, each shape with different offsets. I came across this demo on the official website and modified it to create my own demo, featuring various s ...

Issues with AngularJS routing functionality are causing it to malfunction

Having Trouble with My Angular Routing Function - Page Loads Without 'home.html' Here is the code I am using: Index.html <html ng-app="App" class="no-js" lang="en" > <head> <script src="https://ajax.googleapis.com/ajax/libs ...

Exploring the concept of type inheritance in TypeScript

I am working on developing various components for an app, each with its own specific structure. The general structure is defined as COMPONENT. Within this framework, there are two distinct components: HEADING and TEXT. These components should be subclasses ...

Using Selenium with Python to interact with a dynamically generated object that does not have an identifying id or name

Whenever a Right click is performed, an options popup/screen will appear with dynamic content/element. Here is the Options Popup: https://i.stack.imgur.com/TfxpC.png This dynamic content/element will disappear as soon as the mouse is clicked elsewhere o ...

Importing JWT in ES6SyntaxCreating ES6 imports

I'm currently developing a nodeJS web application and utilizing JWT for authentication. My code is all written in ES6 modules, so I wanted to import JWT the same way. However, it seems that the package does not fully support this method yet. Since I&a ...

Block users from printing in text input with Angular

I need to restrict users from entering text into a specific input field, even though they can click on it and select the value. Using the disabled attribute is not an option because it triggers another event when clicked. I also want users to have the ab ...

Design a search page with expandable fields for a user-friendly experience

Initially, my search page displays 12 fields. I would like to add a link labeled "MORE" that will reveal an additional 10 fields, including the original ones. If the user clicks on "HIDE," these extra 10 fields will disappear as well. ...

filter out null values from JSON using gson

I am looking for a way to eliminate attributes with empty collections or null values using gson. Aiperiodo periodo = periodoService(); //periodo is obtained from a service method with various values Gson gson = new Gson(); String json = gson.toJson(period ...

Having trouble incorporating a bootstrap template into my Angular project: Whenever I add the styling files, the application ceases to function

I'm currently working on incorporating a Bootstrap template into my Angular project, which already utilizes Bootstrap. Check out my Angular project https://i.sstatic.net/SKzRk.png. Now, I'm focusing on integrating the "Ethereal" scrolling templa ...

Surprising Media Component Found in URL Parameters within the design

Exploring the page structure of my Next.js project: events/[eventId] Within the events directory, I have a layout that is shared between both the main events page and the individual event pages(events/[eventId]). The layout includes a simple video backgro ...

Eliminate properties from a TypeScript interface object

After receiving a JSON response and storing it in MongoDB, I noticed that unnecessary fields are also being stored in the database. Is there a way to remove these unnecessary fields? interface Test{ name:string }; const temp :Test = JSON.parse('{ ...

Getting the current URL in InApp browser on Phonegap 3.0: A quick guide

Hey there, I am having trouble retrieving the current URL of an in-app browser when clicking the close button or at any time after loading a URL. Here's my code: var ref = window.open('http://google.com', '_blank', 'hidden=y ...

Change Node.js version to 6.11.5 on a Windows system

My current node version is v8.2.1, but Google Cloud Functions only supports v6.11.5. I need to switch my node version accordingly and preferably do it using npm. How can I achieve this? I have explored How to change to an older version of node.js for guid ...

Customized AngularJS URLs

After gaining proficiency in BackboneJS and AMD, I have successfully completed multiple large projects. Now delving into AngularJS, I have already implemented it with AMD and created controllers and services with ease. The only challenge I'm facing i ...

Multiple consecutive XHR requests failed without any error message. The cause remains unknown

Here is the content of my package.json file: canActivate in my code:</p> imports: [ BrowserModule, FormsModule, ReactiveFormsModule, RouterModule.forRoot([ {//route configs path: '', redirectTo: '/cfbsetup', pathMatch: &a ...