Skip to content

Commit

Permalink
fix(client:main): fix add/delete things
Browse files Browse the repository at this point in the history
  • Loading branch information
Awk34 committed May 13, 2017
1 parent b0e01af commit 91b920b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions templates/app/client/app/main/main.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,24 @@ export class MainComponent implements OnInit<% if(filters.socketio) { %>, OnDest

addThing() {
if(this.newThing) {
this.Http.post('/api/things', { name: this.newThing });
let text = this.newThing;
this.newThing = '';

return this.Http.post('/api/things', { name: text })
.map(res => res.json())
.catch(err => Observable.throw(err.json().error || 'Server error'))
.subscribe(thing => {
this.awesomeThings.push(thing);
});
}
}

deleteThing(thing) {
this.Http.delete(`/api/things/${thing._id}`);
return this.Http.delete(`/api/things/${thing._id}`)
.map(res => res.json())
.catch(err => Observable.throw(err.json().error || 'Server error'))
.subscribe(() => {
this.awesomeThings.splice(this.awesomeThings.findIndex(el => el._id === thing._id), 1);
});
}<% } %>
}

0 comments on commit 91b920b

Please sign in to comment.