ETA: I know that there are various ways to see my form of change. This is not what I'm trying to do. As the name says, I ask how to track changes in an object. The application shown below is for illustration purposes only. Please answer the question I asked. Thanks!
I have this simple application:
import { Component, OnInit } from '@angular/core'; export class Customer { firstName: string; favoriteColor: string; } @Component({ selector: 'my-app', template: ` <div *ngIf="customer"> <input type="text" [(ngModel)]="customer.firstName"> <input type="text" [(ngModel)]="customer.favoriteColor"> </div> ` }) export class AppComponent implements OnInit { private customer: Customer; ngOnInit(): void { this.customer = new Customer();
Pay attention to TODO. I need to register a callback that will be executed whenever any this.customer property is this.customer .
I cannot use ngChange on inputs. I need to subscribe directly to changes to the model. The reasons relate to my precedent and should not be included here. Just believe me, this is not an option.
Is it possible? I did a lot of googling, but I came up with a dry one.
javascript angular typescript
greenie2600
source share