Skip to content

Commit b272802

Browse files
authored
Merge pull request #2568 from angular-fullstack/fix/canary-things
fix(client:main): fix add/delete things
2 parents 04300fc + 91b920b commit b272802

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Diff for: templates/app/client/app/main/main.component.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,24 @@ export class MainComponent implements OnInit<% if(filters.socketio) { %>, OnDest
4343

4444
addThing() {
4545
if(this.newThing) {
46-
this.Http.post('/api/things', { name: this.newThing });
46+
let text = this.newThing;
4747
this.newThing = '';
48+
49+
return this.Http.post('/api/things', { name: text })
50+
.map(res => res.json())
51+
.catch(err => Observable.throw(err.json().error || 'Server error'))
52+
.subscribe(thing => {
53+
this.awesomeThings.push(thing);
54+
});
4855
}
4956
}
5057

5158
deleteThing(thing) {
52-
this.Http.delete(`/api/things/${thing._id}`);
59+
return this.Http.delete(`/api/things/${thing._id}`)
60+
.map(res => res.json())
61+
.catch(err => Observable.throw(err.json().error || 'Server error'))
62+
.subscribe(() => {
63+
this.awesomeThings.splice(this.awesomeThings.findIndex(el => el._id === thing._id), 1);
64+
});
5365
}<% } %>
5466
}

0 commit comments

Comments
 (0)