Hi Asger,

Depends a bit on your take on what a model actually is. My experience 
learns me that a model is usually just the name tagged on a JSON object 
holding the data. In a few cases, the validation is part of the model. 
Also, the validation rules are shared among most models.
For a project, I'm currently working on I wrote a function that takes the 
result of a backend endpoint, and generates the interface for that. Saves 
me a lot of typing, and helps if I need to use the models inside my 
If you want to create self-contained classes out of your models this is 
also an option, just generate a class instead of an interface, and inherit 
the validations from an abstract validation class. This abstract class 
might even contain the CRUD methods that are needed to handle the 
communication with the backend.

And no, you are not supposed to do this. It's a recommended pattern, but 
not the only one. There are more ways on how this can be handled.
The simplest case, just a generic model interface, something like this:

export interface model {
    id?: String;
    [others: string]: any;

That can function as a generic wrapper for all of your models, and it will 
get rid of all 'property' unknown errors in your code.


You received this message because you are subscribed to the Google Groups 
"Angular" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to