default radio button selection problem

When working with reactive forms, I am facing an issue where the radio buttons are not being checked by default even though I am using form values for that purpose. Additionally, when I click on the first currency symbol, the numbers change but the default number is not checked. What I want is for 25000 to be automatically checked when clicking on the first symbol. How can I achieve this? You can view my code on StackBlitz.

I have attempted to change the value on click but it does not seem to work as expected. Here is a snippet of what I have tried:

  lari() {
    this.currencySymbol = "₾";
    let amount = (this.formGroup.get("formArray") as FormArray)
      .at(1)
      .get("amount").value;
    amount = "25000";
    this.currencySymbol = "₾";
    this.amountArray = [
      {
        value: 25000
      },
      {
        value: 50000
      },
      {
        value: 75000
      },
      {
        value: 100000
      }
    ];
  }

Answer №1

To assign the default value, we can utilize the setValue method:

(this.formGroup.get("formArray") as FormArray)
      .at(1)
      .get("amount").setValue("25000");

I have made modifications to the StackBlitz demo provided. Kindly review and confirm.

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

Warning: The use of the outdated folder mapping "./" in the "exports" field for module resolution in the package located at node_modulespostcsspackage.json is deprecated

I recently upgraded my Node to version 16 and since then I have been encountering this issue while building my Angular app. Warning: The folder mapping "./" used in the "exports" field of the package located at ".../node_modules/postcss/package.json" is de ...

Encountering error TS2305 in Visual Studio Code while working with moment.js in an example from an Angular Material

After referencing the code snippet from https://material.angular.io/components/datepicker/overview#choosing-a-date-implementation-and-date-format-settings, I encountered an issue. While the code successfully compiles and runs, Visual Studio Code flagged an ...

What is the functionality of the node class within a doubly linked list?

Within the Node class, the next property can only be assigned a value of type Node or null. class Node { value: any; next: Node | null; prev: Node | null; constructor(value: any) { this.value = value; this.next = null; this.prev = null ...

Make sure to send individual requests in Angular instead of sending them all at once

I am looking to adjust this function so that it sends these two file ids in separate requests: return this.upload(myForm).pipe( take(1), switchMap(res => { body.user.profilePic = res.data.profilePic; body.user.coverPic = res.data.coverPic; ...

Uploading files into an array using Angular 2

Struggling to incorporate an uploader within an array: I've got an array of users displayed in a table using "ng-repeat". I want to add a column with a button to upload an image for each user. Currently, I'm utilizing ng2-file-upload, but open t ...

Error in syntax: The tailwind import statement contains an unrecognized word and will not function correctly

After configuring Tailwind CSS with Next.js, I made changes to the tailwind.config.js file. However, after making these changes, the compilation process failed and resulted in the following error: Error - ./src/assets/styles/global.css:3:1 Syntax error: Un ...

Strategies for Handling Errors within Observable Subscriptions in Angular

While working with code from themes written in the latest Angular versions and doing research online, I've noticed that many developers neglect error handling when it comes to subscription. My question is: When is it necessary to handle errors in an ...

Issue with TypeScript: "Cannot find name" error encountered during yarn build

I'm encountering an issue with my .tsx component code below: const Header = ({ dict: map, lang: string }) => { return ( <header className="flex items-center justify-between py-10"> <div> <Link href={`/${ ...

Using TypeScript with React Router to access the isActive property on NavLink

Currently, I am utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="55273034362178273a2021302778313a3815637b6167">[email protected]</a> and have implemented the following react component: import { Link as Nav ...

Guide on properly documenting custom function types in JSDoc or TypeScript to ensure accurate referencing for VSCode IntelliSense functionality

I am currently working on documenting custom function types within an object and would greatly appreciate any assistance: A Closer Look at the Issue Consider this basic object declaration with several function properties (addCoordinate, addCoordinateOne, ...

Injecting universal data into ValidationErrors in Angular

Trying to bind a value into ValidationErrors. Having this method: isUniqueEmail(control: FormControl): ValidationErrors { if (control.value != null) { console.log(control.value) if(control.value == this.foundEmail){ console ...

Oops! The OPENAI_API_KEY environment variable seems to be missing or empty. I'm scratching my head trying to figure out why it's not being recognized

Currently working on a project in next.js through replit and attempting to integrate OpenAI, but struggling with getting it to recognize my API key. The key is correctly added as a secret (similar to .env.local for those unfamiliar with replit), yet I keep ...

What is the best way to change the value in a ReplaySubject?

I am looking to retrieve the current value and invert it: private controlActive$ = new ReplaySubject<Tool>(); if(this.type === "A") { this.controlActive$.next(!this.controlActive$.getValue()); } Is there a more eloquent way to achieve this? ...

Generating output from a callback function in TypeScript

When I execute a graphql query, the showUsers function is supposed to display all users (styled as boxes). However, at the moment, nothing is showing up. I am utilizing a functional component instead of a class component. This function is invoked after m ...

What is the best way to consistently position a particular row at the bottom of the table in AG-grid?

I have successfully implemented a table using AG-grid. Here is the code snippet: .HTML <ag-grid-angular #agGrid style="width: 100%; height: 100%; font-size: 12px;" class="ag-theme-alpine" [rowData]=&quo ...

Is it possible to capture user input using a rich text editor such as Quill and save the data as a .json file by sending a POST request?

My website features a sophisticated text editor known as ngx-quill, where users can input their content. I am currently working on a project that requires me to generate a JSON file containing user input and then submit this JSON file. I am seeking guidan ...

What is the best way to track events in angular-meteor when a user logs in, logs out, or when there is a change in the user

I am working on meteor-angular and trying to track new user login and logout changes within a single component. I have attempted to subscribe to userData in the component's initialization, but it does not seem to detect when the user logs in or out. I ...

What is the necessity of ngrx/store when services and localStorages are available for use?

When it comes to Angular, we rely on ngrx/store to manage the state. However, I question whether all tasks can be effectively handled using services alone. What benefits does implementing the ngrx/store package offer? Your insights would be greatly appre ...

Issues with patching values in Angular 5 reactive forms when dealing with nested input fields

Currently, I am utilizing Angular 5 along with reactive forms. My form is being dynamically generated based on JSON data provided by the backend. While my structure works well with radio buttons, I encounter an issue when dealing with nested checkboxes at ...

Struggling to integrate Docker compatibility into an established NextJS project, encountering the frustrating "stat app/.next/standalone: file does not exist" message

I'm currently in the process of enhancing my existing NextJS + TypeScript project with Docker support and preparing to deploy it on Google Cloud Run. To achieve this, I've been referring to a helpful guide available at: https://github.com/vercel/ ...