The function setValue is not recognized

As I work on creating a data-driven form in Ionic 2 with multiple fields, I encountered an issue while trying to manually update one control's value when the form changes. The error message that keeps appearing is "

TypeError: _this.myForm.controls.name.setValue is not a function
". Despite experimenting with both with and without the <FormControl> type cast, the problem persists.

import { Component } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators, REACTIVE_FORM_DIRECTIVES } from '@angular/forms';

@Component({
     templateUrl: 'build/pages/lead-provider/add-bp/add-bp.html',
     directives: [REACTIVE_FORM_DIRECTIVES]
 })
 export class AddBpPage {
     private myForm: FormGroup;

     constructor(private formBuilder: FormBuilder) {
         this.myForm= formBuilder.group({
             'name': ['', [Validators.required]],
             'email': ['', [Validators.required]],
             'phone': ['', [Validators.required]]
         });

         this.myForm.valueChanges.subscribe((value) => {
             (<FormControl>this.myForm.controls['name']).setValue('abc');
         });
     }
}

Answer №1

setValue was implemented just a couple of weeks ago, so RC.4 may not have integrated it yet.

Instead, try using updateValueAndValidity()

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

Encountered an issue during the transition from Angular 7 to Angular 9

After following the advice in the second response of this discussion, I successfully upgraded to Angular 9. However, I am now encountering an issue in the browser console when running my project. https://i.sstatic.net/esAXf.png Package.json "dependencie ...

Typed method decorations in TypeScript provide robust type checking and enforcement in your codebase

I am currently working with TypeScript code that involves listening to events based on topics generated from specific contexts. I am looking to streamline the event registration process by utilizing method decorators. For instance, I have a "Controller" c ...

What is preventing Angular from letting me pass a parameter to a function in a provider's useFactory method?

app.module.ts bootstrap: [AppComponent], declarations: [AppComponent], imports: [ CoreModule, HelloFrameworkModule, ], providers: [{ provide: Logger, useFactory: loggerProviderFunc(1), }] ...

Is there a way to prevent the openlayers (4) map from redrawing when overflowing at the edges?

At the moment, my map keeps redrawing itself when I overflow the view, as shown in the image here: https://i.sstatic.net/xpyiP.png The countries displayed on the map are represented by simple geojson polygons. However, I want the map to stay fixed and n ...

The fuse-sidebar elements are not being properly highlighted by Introjs

I have recently developed an angular project that utilizes the fuse-sidebar component. Additionally, I am incorporating introjs into the project. While introjs is functioning properly, it does not highlight elements contained within the fuse-sidebar. The ...

The information displayed in the charts generated by charts.js dynamically updates as I interact with the line chart by clicking on

I've integrated charts.js to display various charts in my angular-ionic app. The issue arises when the state changes and I update the chart data accordingly, but the graphs fail to refresh unless each chart is clicked individually. Additionally, upon ...

Customize CSS styles based on Angular material stepper orientation

Is it possible to change the CSS style of an angular material stepper based on its orientation? For instance, can we set a red background when the stepper is displayed vertically and a blue background when horizontal? ...

Encountering a difficulty in adding an item to Firebase

I'm currently tackling a project using Angular and Firebase. Unfortunately, I'm facing some challenges when attempting to push an object to the Firebase Database. If you'd like to take a closer look at the issue, check out this Stackblitz E ...

Is there a C# counterpart to TypeScript's Template Literal Types?

Recently, I've encountered a scenario in my C# project where I need to handle a SQL sort order parameter within a function: public static string BuildSortClause(string colId, string sortOrder) { ... } Specifically, I want to ensure that only &apos ...

I'm looking for the configuration of function definitions for the Jasmine npm module within an Angular project. Can

When a new Angular project is created, the *.spec.ts files provide access to Jasmine functions such as "describe", "beforeEach", and expect. Despite not having an import clause for them in spec.ts files, I can click on these functions and navigate to their ...

Ways to verify the data types of elements within an array

How can I determine the types of values in a string[] | object[] array to perform different operations based on the value type? I attempted to check the type of the first item in the array, but TypeScript does not recognize it and still considers it as st ...

Optimize your code in Angular 5 by consolidating or restructuring numerous Subscribe calls

Currently, I am utilizing Angular 5.2 for my web project. One of the pages includes multiple subscribe calls to various webAPI methods. While these calls are distinct and retrieve different datasets, I'm contemplating if there is a method to consolida ...

What is the best method to select pagination in a Spring Boot application?

I am seeking advice on implementing pagination for my table data in a Spring Boot application. The dataset is quite long, so I have implemented pagination to retrieve the data from the database efficiently. Currently, I have a REST method in my Spring Boo ...

Why bother with creating mappers to transform entity-to-DTOs?

There are classes referred to as 'mappers' that are utilized by some individuals for converting DTOs to entities or vice versa. What benefits do I stand to gain from employing this technique during backend development? I am keen on delving deepe ...

What is the best way to assign a value to a class variable within a method by referencing the 'this' keyword?

Is there a way to set the state of this Ionic react app when displaying the outcome of a reset service? I am facing challenges with using this.setState({resetSuccess}) within a method due to scope issues. (Details provided in comments) Here is the relevan ...

The <mat-radio-button> component does not have a value accessor specified

When working with HTML and Angular, I encountered the following issue: <mat-radio-group> <mat-radio-button [(ngModel)]="searchType"> And (Narrower search) </mat-radio-button> <mat-radio-button [(ngModel)]="searchType"&g ...

Determine the index of items within an array of objects in Lodash where a boolean property is set to true

I am new to using lodash after transitioning from C# where I occasionally used LINQ. I have discovered that lodash can be utilized for querying in a LINQ-style manner, but I'm struggling to retrieve the indexes of items in an array of objects with a b ...

Is it considered an anti-pattern in TypeScript to utilize BehaviorSubject for class or object properties?

When working with Angular, I find myself frequently displaying members of classes in an Angular HTML template. These classes often share common members structured like this: class Foo { bar: string; bas: Date; } There are instances where I need to ...

Error: Cannot find definition of Chart in conjunction with primeNg and angular 4

An error occurs when I remove the following line from my index.html file <script src="node_modules/chart.js/dist/Chart.js"></script> Is it possible to eliminate this line from index.html and instead include the equivalent line in my systemjs. ...

Typescript void negation: requiring functions to not return void

How can I ensure a function always returns a value in TypeScript? Due to the fact that void is a subtype of any, I haven't been able to find any generics that successfully exclude void from any. My current workaround looks like this: type NotVoid ...