Aaron Lind
Aaron Lind

Reputation: 415

Angular Model From Server

I'm new to Angular and I just can't get my head wrapped around this idea, any help would be greatly appreciated.

A lot of conversations state the Model should come from the server via restful web services. I've been using $http in a factory. This makes sense to me "if" there is data present. If you load a screen and the user or whatever is new then you get a blank JSON value. For complex data (relationships) you get those items with a value but other properties are left off.

So what am I missing here, how can the model come from the server consistently?

Upvotes: 0

Views: 204

Answers (2)

samir benzenine
samir benzenine

Reputation: 478

You could take advantage of standard HTTP status codes as a mechanism to provide results to the client:

for example, your service could return an HTTP code of 204 to indicate that the server successfully processed the request, but is not returning any content.

Upvotes: 0

David Sung Lee
David Sung Lee

Reputation: 288

It's useful to think of your model as both a server model and a client model. The server model should be your true model or "source of truth", and the client model is a working model or "mimic" that should behave as a local copy of the server model.

For the model to "come from the server consistently", you have to ensure that any changes to the client model get validated by the server side. Meaning that when any change requests to the model -- such as create, remove, update, or delete (crud) -- get sent as requests to the server, and then the resulting changed data model gets returned to the client model so it can be updated.

Upvotes: 1

Related Questions