Component using ControlValueAccessor failing to update value within formgroup in Angular 7

I am currently working with Angular 7 and have created a child component using 'ControlValueAccessor'. Within this component, I have included a combobox and textbox in my form. The issue I am facing is that when I select an item from the combobox, the value is correctly set to the textbox. However, when I click on the "SAVE" button, the form value appears as empty. What could be causing this to happen?

Check out the code on StackBlitz

Answer №1

For optimal functionality, you will need to implement 2 key changes.

To begin with, your onChange() method currently lacks any functionality.

Update it to

public onChange: (value) => void
.

Then, ensure that you call this.onChange(selected) after assigning the selected value to the value property within your set selectedItem(selected), as demonstrated here:

set selectedItem(selected) {
    this.value = selected;
    this.onChange(selected);
} 

Take a look at the updated stackblitz example

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

Ways to convert an asynchronous operation to synchronous in JavaScript

Currently in the process of developing an eslint plugin, I have come across a particular issue. My goal is to implement real-time changes to the configuration file by making an HTTP request to retrieve the JSON configuration. When attempting to execute co ...

Beware of potential issues with FontAwesomeIcon when incorporating it into a Typescript file

I'm currently working with NextJS and Typescript. I encountered an issue when trying to import FontAwesomeIcon like this <FontAwesomeIcon icon={faCheck as any} /> as it triggered a warning in the console stating "Warning: FontAwesomeIcon: Suppor ...

Display customizable template according to variable

The answer provided for the issue regarding dynamic template generation based on value instead of variable in this thread was really helpful. However, I'm facing challenges in getting it to work. Here's a simplified example: export class A { } ...

Increasing the proxy port in Angular 11 to resolve CORS issues

I am observing a situation that is causing concern and I believe it may be the root of my problem: https://i.sstatic.net/djZM5.png When trying to access 'https://localhost:5001/calls/api/Auth/register' (originally from 'http://localhost:420 ...

Facing problem with implementing NgMoudleFactoryLoader for lazy loading in Angular 8

A situation arose where I needed to lazy load a popups module outside of the regular router lazy-loading. In order to achieve this, I made the following adjustments: angular.json "architect": { "build": { ... "options": { ... "lazyM ...

Retrieve information from matSnackBar using openFromComponent

Hello there! As a newcomer to Angular, I am interested in retrieving data from matsnackbar. Is this something that can be achieved? apiName: string; this.snackBar.openFromComponent(CustomSnackbarComponent, { duration: 5000000, dat ...

A call signature is missing in the expression type of Typescript, preventing it from being invoked

While I know there are similar questions out there, none of them have provided the answer I'm looking for. My goal is to create a straightforward function in my Angular application. In my app.component.ts file: formClick() { const formContainer ...

Tips on transforming Angular 2/4 Reactive Forms custom validation Promise code into Observable design?

After a delay of 1500ms, this snippet for custom validation in reactive forms adds emailIsTaken: true to the errors object of the emailAddress formControl when the user inputs [email protected]. https://i.stack.imgur.com/4oZ6w.png takenEmailAddress( ...

Is there a way for me to extract a parameter from the URL using ActivatedRoute in my component's constructor?

In my constructor, I am currently following this approach: this.articleSlug = _route.url._value[1].path; However, TypeScript throws an error: Property "_value" is not found on type Observable<Params> Is there a more efficient way to achieve this? ...

The argument list must contain at least one type

Currently, I am executing my code snippet private convertToItemsValidationTo(selectedRows: DetailsTo[]) { if (!selectedRows || selectedRows.length === 0) { return; } (...) itemsValidationTo.convertedVlues = new Map<>(); selectedRows.forEach(row = ...

Next.js: Specify HTTP response code

I am working on a Next.js v12 application that is written in TypeScript. Within this application, I have created a custom error page called _error.tsx to provide a user-friendly experience for various errors such as 410, 404, and more. The issue I am faci ...

Ways to incorporate StropheJs into Angular 8

Methods I have attempted: Method 1: Downloaded the strophejs-1.3.4.zip from Unzipped the folder, strophejs-1.3.4, and placed it in the src/assets directory of my Angular 8 project. Included the following in my index.html file: <!--// Stroph ...

The object literal's property 'children' is assumed to have a type of 'any[]' by default

Is there a way to assign the property myOtherKey with any value? I encountered a Typescript error that says.. A problem occurred while initializing an object. The property 'children' in the object literal implicitly has an array type of 'a ...

I am seeking advice on how to create an extension for a generic class in TypeScript specifically as a getter

Recently, I discovered how to create extensions in TypeScript: interface Array<T> { lastIndex(): number } Array.prototype.lastIndex = function (): number { return this.length - 1 } Now, I want to figure out how to make a getter from it. For exam ...

Is it necessary for a method to be async if browser.wait is used within it?

Just starting out with typescript, so go easy on me. I'm currently refactoring some selenium tests using protractor and angular. I've created a method to wrap browser.wait(ExpectedConditions.presenceOf(element)); My tests were passing fine wh ...

Incorporating router links into a paragraph with Angular and NativeScript

Is there a way to format a paragraph or sentence containing multiple text links that are internal router links, not external web links? It appears that text can be formatted using FormattedString and Span, but it also seems that nsRouterLink cannot be add ...

Drag and drop functionality in Angular 2 using TypeScript

Has anyone experimented with the drag and drop functionality using Angular2 RC with TypeScript? Thanks, Sanket ...

What steps can I take to ensure my CSS selector for the element is functioning properly?

Here is an example of some code: <html> <head> <style> .test{ background-color: red; p { background-color: yellow; } } </style> </head> <body> <div class="test"> ...

What is the process for including a selected-by option in a VIS network graph?

I'm trying to outline the neighboring nodes of the node that has been selected (highlightNearest). https://i.sstatic.net/lynhu.png Unfortunately, I haven't had success achieving this using JavaScript. Link to StackBlitz ...

Choosing everything with ngrx/entity results in not selecting anything

Issue with Selector I am facing an issue with my selector in the component. Despite making the call, the component does not update with books from the FakeApiService. The actions and effects seem to be functioning correctly. The problem seems to be relat ...