Angular2 how do you listen for changes to data in a class?

I have an array containing class User. This array is presented through an *ngFor as repeated <li> items. The user can click on these items and get the detail for a user in a detail control.

The fields in the detail control are bound using [(ngModel)].

I am trying to figure out how to detect when a user has changed the data in a particular user so that I can mark it dirty and only send modified users back to the web service. I would also like to stop the user from navigating away with unsaved data.

In C# I would use the INotifyPropertyChanged interface to accomplish this.

I have been looking at the ngOnChanges and onchange but these don’t seem to be what I am looking for.

Any assistance would be awesome.

Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
newest oldest most voted
Notify of

If you use a <form> for the input fields where you edit the user, than the form provides the information whether something was changed.