The custom component in ngx-formly remains unchanged after updating the model

I am utilizing custom component fields in my project.

Initially, everything works smoothly until I attempt to replace the model with a different one.

Unfortunately, the component for each field does not get updated with the new value.

No events seem to trigger either.

This is how I am trying to change the model:

this.model = this.data.model[this.currentRow];

The HTML Formly tag used:

<form class="formly" role="form" [formGroup]="form" >

    <formly-form #formly [(model)]="model" [fields]="fields" [form]="form" [options]="options">

    </formly-form>

  </form>

</div>

In app.model.ts file:

FormlyModule.forRoot({
      types: [
        { name: 'customTextNumeric', component: VerticalNumericEditorComponent},        
        { name: 'customDatepicker', component: VerticalDatePickerComponent },
        { name: 'customSelect', component: VerticalSelectComponent },
.

. .

An example of my custom component code:

import { Component, OnInit, Input, ViewChild, SimpleChanges } from '@angular/core';

import { FieldType } from '@ngx-formly/core';
import { FormControl, FormGroupDirective, NgForm, Validators } from '@angular/forms';
import { ErrorStateMatcher } from '@angular/material/core';
import { SearchLabelService } from '../../tableHandle/search-label.service';

/** Error when invalid control is dirty, touched, or submitted. */

export class MyErrorStateMatcher implements ErrorStateMatcher {

  isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
        const isSubmitted = form && form.submitted;
        return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted));
      }
    }

@Component({
      selector: 'app-vertical-numeric-editor',
      templateUrl: './vertical-numeric-editor.component.html',
      styleUrls: ['./vertical-numeric-editor.component.css']
    })

export class VerticalNumericEditorComponent extends FieldType {

  private validates = [];
      private initialValue;
      private value;



  private validateValues = { required: false, minLen: 0, maxLen: 99999999, pattern: '' };

  constructor(private labelSearch: SearchLabelService) {
        super();
        this.numericFormControl = new FormControl('', this.validates);
        console.log('constructor field:');
      }

  numericFormControl: FormControl;

  onInit() {
        console.log('oninit');
      }

  matcher = new MyErrorStateMatcher();

  ngOnInit() {
      }


  OnChanges(e) {
        console.log('on changes');
      }



  ngDoCheck() {
      }

  ngOnDestroy() {
      }

  get type() {
        return this.to.type || 'text';
      }
    }

Does anyone have any suggestions on how to update the component with the new value?

Answer №1

For more information, please refer to the following GitHub issue: https://github.com/formly-js/ngx-formly/issues/975

It appears that the issue may vary depending on how you update your model (whether it involves updating a single field or not).

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 sleek navigation bar and sliding feature within the header of your Ionic 2

I am looking to create a sliding header for my website where the gallery hides and the navbar moves to the top as I scroll down, similar to the gif provided. Any help or ideas on how to achieve this would be greatly appreciated. Thank you. https://i.sstat ...

Javascript ajax async data update has encountered a failure

Utilizing HTML, javascript, and Nodejs coding to create a chrome extension. When the page loads, the function getBalance() is invoked to retrieve data and display it in an HTML span. Below is the code snippet: function getBalance() { var request = new ...

When incorporating pinia with Vue, encountering an error with the decorator that says "Error: Unable to access 'useCoreStore' before initialization" may happen

While implementing the vue-facing decorator in my current project, I encountered an issue with setting up pinia. The structure of my component resembles the example provided here: I have verified that decorators like @Setup are functioning correctly, ind ...

Guide on creating multiple instances of vue-multiselect with a simple button click

I am trying to implement a vue-multiselect dropdown with the addition of a new dropdown upon clicking an "add more" button. However, I am currently unsure of the best approach to achieve this. Problem/Question: When adding 2 dropdowns, if the same option ...

Angular: Ensuring Paypal button does not display twice without a hard reload

I have encountered an issue with a PayPal payment button on my page. The button displays fine when I generate it for the first time, but if I try to generate it again for another order, it doesn't show up. I have to hard reload the page to get it to w ...

What is the reason for the request producing additional data beyond what was input into the interface?

When making a request for an API that contains multiple values, it can be frustrating when unwanted values are included in the response. To address this issue, interfaces are created to accurately define and use the necessary objects. However, the object ...

Differences Between Angular Event Emitter and Click Listener

I've been delving into Angular by exploring the "Your First App" section on their official website. One aspect that has caught my attention is the event emitter functionality. In the Parent Component (product-list): <app-product-alerts [produc ...

Ways to optimize image focus on a webpage

Upon loading the page, I desire for my image to be automatically focused. Unfortunately, setting the tabindex parameter has not produced the desired outcome. This is likely due to the fact that there are multiple angular2 header components with defined t ...

Utilize OpenLayer3 to showcase Markers and Popups on your map

I am currently exploring how to show markers/popups on an osm map using openlayers3. While I have come across some examples on the ol3 webpage, I'm interested in finding more examples for coding markers/popups with javascript or jquery, similar to som ...

Adjusting the size of HighCharts HighMaps with a custom function

Simple query here (I believe) I have a DIV with the class "container" acting as my Map. The Highcharts plugin I'm using is responsive, but it only resizes when the window does. I'm looking to manually trigger a resize without adjusting my windo ...

Angular Iterate Array Forms

Is there a way to iterate my rows based on user input? For example, if the user enters 2 values, I need to display 2 rows. How can I achieve this using FormArray? setCount(count:any){ console.log(count); this.count = count; this.countArray = Ar ...

Guide on showing a message on the server side when pressing a button in the web browser

I need the following question to function seamlessly on all major browsers including Opera, Internet Explorer, Chrome, Safari, and Firefox I am working on an application that requires users to follow a specific order of pages Text1.php, Text2.php, Text3.p ...

Retrieving information from an external API in response to an express GET request

After reviewing the sample code in the gtfs-realtime-bindings library's documentation, I attempted to implement a similar logic within my router. However, I encountered issues with extracting the result from the request() route.get('/', (req ...

The error message 'ReferenceError: MouseEvent is not defined' indicates that

Recently, I attempted to incorporate ng2-select into a project that relies on angular/universal-starter (TypeScript 2.x) as its foundation. (Interestingly, ng2-select worked perfectly fine when added to an angular-cli generated project.) However, upon ad ...

Implement a click event for the X-Axis label in Angular 2 Highcharts

I'm currently facing a challenge with hand-rolling a solution that involves adding a click listener to an X-Axis label in a column chart using the HighCharts API within an Angular 2+ application. Here is what I have gathered so far: I am utilizing ...

Button click event not triggering JavaScript execution

I am experimenting with HTML, PHP and JS and have encountered a problem. Here is my code: <html> <head> <title> Dummy Code </title> <script> sendMail(){ <?php $to = '<a href="/cdn-cgi/l/email-protection" class ...

Guide to importing JavaScript in an npm package using TypeScript and JavaScript

I recently downloaded a library that includes both Typescript and its corresponding javascript version. Despite trying to declare import Library from "@scope/library", my application is only able to access the Typescript version, even after adding the .js ...

Divide a string into an array starting from the end

I have a unique phrase. var phrase = "LoremipsumdolorsitametconsectetuadipiscingelitSeddoeiusmodtemporincididuntutlaboreetaliqua"; I am interested in dividing it into chunks of 11 characters starting from the end. Currently, I use: function splitPhrase ...

Removing a parameter from a link in Vue.js: A step-by-step guide

I currently have the following list of URLs: http://example.com/post?st=1&plt=123&number=1 http://example.com/post?st=1&plt=[exp]&number=1 http://example.com/post/view/12?ex=1&plt=123 http://example.com/post/edit/12?ex=1&tes ...

Determine whether an interface includes a mandatory field

Can Typescript's Conditional Types be used to determine if an interface includes a required field? type AllRequired = { a: string; b: string } type PartiallyRequired = { a: string; b?: string } type Optional = { a?: string; b?: string } // Can we mo ...