Angular form for updating values

In my Angular project, I am utilizing an angular dynamic form where I am populating values using JSON.

  
    data = {
      firstName:"Eliseo",
      lastName:"Plunker",
      myArray:[
        {
          emailAddress:"<a href='/cdn-cgi/l/email-protection' class='__cf_email__' data-cfemail='1570797c66707a556579607b7e70673b767'>
[email protected]</a>",
          brave:"solid"
        },
        {
          emailAddress:"<a href='/cdn-cgi/l/email-protection' class='__cf_email__' data-cfemail='e7828b8e948288a7978b92889e8689d398895880'>[email protected]</a>",
          brave:"great"
        }
      ]
    }
  

Function to patch values:

  
    fillData() {
      this.form = this.qcs.toFormGroup(this.questions);
      for (let i=0;i<this.data.myArray.length;i++) {
        this.addControls('myArray');
      }
      //Use patchValue
      this.form.patchValue(this.data);
    }
  

In the above function, I only want to update the values in myArray and not firstName or lastName.

I attempted with this.data.myArray

    
    this.form.patchValue(this.data.myArray);
  

However, it did not work as expected.

View the working stackblitz: https://stackblitz.com/edit/angular-x4a5b6-wztvq9

Click on the Fill Form button in the demo above to see the updated values in the form.

Please assist me in patching only the myArray value and keeping others empty.

Answer №1

Here's a suggestion for updating myArray values

Try using this.form.patchValue() method:
this.form.patchValue({
  'myArray' : this.data.myArray
});

Give it a try and see if it works for you!

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 a dynamic workspace with a portable viewing window

I am looking to create a spacious workspace for arranging objects, but I also want to incorporate a customizable "viewport" that will display a specific area of the workspace for the user. This viewport should be resizable and movable within the workspace, ...

Error: It appears that the callback with the specified ID for the module <unknown> cannot be found

I decided to create a yarn package that includes common components, services, utils, and more for my project. After creating the package, I added an index.ts file in the src folder to export all components. Once the package was built and added to my projec ...

Mastering all changes to the 'src' attribute in the DOM

I am currently coding in Javascript and trying to implement a feature that monitors new 'script' elements and blocks specific sources. I have experimented with using MutationObserver and __defineSetter__, both of which can monitor changes to the ...

"Optimizing Angular2 with Tree Shaking using Webpack2 and ng

In my angular2 application, I am currently utilizing https://github.com/ng-bootstrap/ng-bootstrap with webpack2 to compile all ts files. At the moment, I am only using the Modal Component from NgbModule. However, even in the minified file, I can still see ...

The jQuery selector is unable to locate the IMG element using its unique ID

I'm experiencing an issue with a webpage that includes the following code snippet: <img class="img-qrcode" id="img_123.000.00.01" src="http://localhost:7777/data/code_img\123.000.00.01.png" alt="./data/code_img\123.000.00.01. ...

Show 1 Blog Post on a Separate AngularJS Page

I would like to show only Test Post 1 on the next HTML page titleDetails.html when the user clicks on Test Post 1 in index.html 1) titleDetails() in index.html: <a ng-click="titleDetails(post)">{{ post.title }} </a> 2) Controller Variables a ...

Arrange a div close to another div with the help of absolute positioning

My goal is to create a tooltip-like positioning for an element within the same container as another element. When clicked, this particular element will display a div containing a table. You can find the complete code here: http://jsbin.com/xihebol When s ...

Different ways to designate the return type of a class constructor, such as utilizing a proxy method

As I venture into the Typescript realm, I have encountered a challenge while experimenting with a Proxy as a return value from a class constructor. Consider the following code snippet: class Container { constructor() { return new Proxy(this, contai ...

JavaScript duplicate function is malfunctioning

Check out this jsfiddle link: https://jsfiddle.net/3o38nbzs/4/ When I clone an object, I am able to move the clone but it does not respond to click events. https://jsfiddle.net/L5mg87jm/ When I clone an object in this example, the clone remains static. T ...

What could be causing the Typescript error when utilizing useContext in combination with React?

I am currently working on creating a Context using useContext with TypeScript. I have encapsulated a function in a separate file named MovieDetailProvider.tsx and included it as a wrapper in my App.tsx file. import { Context, MovieObject } from '../in ...

Master the Art of Scrollbar Control in Angular!

I am currently developing a chat web application that functions similar to gchat. One of the key features I'm trying to implement is an alert notification when the scrollbar is in the middle of the div, indicating a new message. If the scrollbar is at ...

angular change digits to Persian script

I am trying to convert English numbers to Persian numbers in angular 4: persianNumbers = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]; engli ...

AssertionError [ERR_ASSERTION]: The value of undefined is not equal to 390 in the GitLab

I'm a bit confused about the AssertionError [ERR_ASSERTION]: undefined == 390 in Gitlab. What I need is: The sumSalaries(obj) function, which should take an object obj as a parameter where the field names correspond to the employee's name and t ...

React-router can manage non-matching paths by utilizing a basic JavaScript router configuration

Is there a way to manage non-matching paths using plain JavaScript in React router configuration? const rootRoute = { component: 'div', childRoutes: [ { path: '/', component: App, childRoutes: [ requir ...

Ways to identify the current configuration of ckeditor in use

I've created a custom CKEditor plugin with a unique dialog box setup. To include the dialog, I use the following code: var customize_dialog = this.path + 'dialogs/customdialog.js' ; CKEDITOR.dialog.add( myPluginName, customize_dialo ...

Is there a way for me to produce a random choice depending on the option selected by the user in the <select> menu?

As a beginner in JavaScript, I am attempting to create a feature where users can select a genre from a dropdown list and receive a random recommendation from that genre displayed on the screen. In essence, my goal is to allow users to get a random suggest ...

Experiencing a platform browser error since updating to Ionic 5 from Ionic 4

ERROR: Uh-oh! Looks like there's an issue in the node_modules directory. The error message reads: ERROR in node_modules/@angular/platform-browser-dynamic/platform-browser-dynamic.d.ts(15,10): error TS2305: Module '"node_modules/@angular/compiler ...

What are some ways to incorporate Firebase's setPersistence() feature into a React application built with Vite?

In my React project with TypeScript and Vite, using Firebase has presented an issue in the authentication flow. The problem arises when I try to set the persistence type using setPersistence(). Despite what is documented in the official Firebase documenta ...

There was an issue encountered when trying to fill in the details for the Print Queue entity. Win32 error message: The name of the printer provided is

System.Printing.PrintQueueException: An error happened while populating the attributes for the PrintQueue object. Win32 error: The printer name is not valid. When I execute this code in Windows 10, I encounter this issue, although it works perfectly in Wi ...

What is the best way to implement React Router within an if/else statement inside a function triggered by a button click?

const handleStartClick = () => { const userEmail = localStorage.getItem('email') if (userEmail !== null && userEmail.length !== 0) { alert('The email is not empty!') } else { <Routes> ...