Interesting point. I never thought that the generic type you could pass to .get(), .post(), etc, could be used by Angular to perform the conversion. Do you have examples of that being used?
The case for adapters is also handling complex conversions, such as building nested objects and the like. For example, what if GET: /courses/ returned course objects with a students field, representing a list of Student objects? Can generic type conversion handle that?
Also, how can generic type conversion decide to build a Date object out of the created field (a string)?
That code snippet works like a charm i’m using it currently it been like that since angular 5 or 4 not sure, your right about the date thingy but if you send it from backend as a date type. You’ll get it as a date type too in angular.
Interesting point. I never thought that the generic type you could pass to
.get()
,.post()
, etc, could be used by Angular to perform the conversion. Do you have examples of that being used?The case for adapters is also handling complex conversions, such as building nested objects and the like. For example, what if
GET: /courses/
returned course objects with astudents
field, representing a list ofStudent
objects? Can generic type conversion handle that?Also, how can generic type conversion decide to build a
Date
object out of thecreated
field (a string)?Happy to discuss further. :)
That code snippet works like a charm i’m using it currently it been like that since angular 5 or 4 not sure, your right about the date thingy but if you send it from backend as a date type. You’ll get it as a date type too in angular.
Cool! Glad to hear simple type conversions work.
To my knowledge there is no
Date
type in JSON, though, so that still means the model-adapter pattern is needed in more complex use cases.In typescript/JavaScript there is obviously, you’ll access it like a normal property Obj.dateProperty