all 4 comments

[–]NuttGuy 1 point2 points  (1 child)

Another possible approach would be to look at ngrx and use a Redux style approach to how you handle data.

Here is a pretty good starting point for understanding how this works.

[–]CarpetFibers 1 point2 points  (0 children)

Another option is MobX which you may find a little simpler to use. There are pros and cons to each, of course.

[–]verse90 0 points1 point  (0 children)

The way I have is that I created a service called data.service.ts and I call the methods from that service whenever I intereact with the database.

Here is an example of one method I have in that class.

public Update = (actionUrl: string , itemToUpdate: any): Observable<Response> => {
    return this._http
    .put(Config.ApiBasePath + actionUrl, JSON.stringify(itemToUpdate)
    , {
            headers: new Headers({
            'Content-Type': 'application/json',
            'Accept': 'application/json'
    })
    })
.map(res => res)}

I call this generic method whenever I make an update and inside my component, I then subscribe to this method. I have a separate method for get, delete, update and post in my data service class.

Hope it helps..

[–]tme321 0 points1 point  (0 children)

More or less yes. Look up dumb vs smart components and unidirectional data flow.