Difference between revisions of "Using Angular HttpClient"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) (Created page with "=Links= * * =Examples= Some examples. ==GET== <pre> getUsers() { this.httpClient.get(this.url').subscribe((res: any[]) => { console.log(res); this....") |
PeterHarding (talk | contribs) |
||
Line 34: | Line 34: | ||
</pre> | </pre> | ||
=PATCH= | |||
<pre> | |||
update(xxx: Xxx) { | |||
this.httpClient.patch(this.baseUrl + '/v1/xxx/xxxx-xxxx/' + this.id, | |||
{ | |||
Id : xxx.Id, | |||
Status: xxx.Status, | |||
XxxId: xxx.XxxId, | |||
NoXxx: xxx.NoXxx | |||
}) | |||
.subscribe( | |||
data => { | |||
console.log('[update] PATCH Request is successful |' + data + '|'); | |||
return data; | |||
}, | |||
error => { | |||
console.log('[update] Error |' + error + '|'); | |||
return error; | |||
}); | |||
} // update | |||
</pre> | |||
[[Category:Angular]] | [[Category:Angular]] |
Revision as of 10:44, 24 October 2019
Links
Examples
Some examples.
GET
getUsers() { this.httpClient.get(this.url').subscribe((res: any[]) => { console.log(res); this.users = res; }, error => { this.errorMessage = error as any; }, () => { // Complete - update a datatable this.changeDetectorRef.detectChanges(); const table: any = $('#UsersTable'); this.dataTable = table.DataTable(this.dtOptions); }); } // getUsers
POST
PATCH
update(xxx: Xxx) { this.httpClient.patch(this.baseUrl + '/v1/xxx/xxxx-xxxx/' + this.id, { Id : xxx.Id, Status: xxx.Status, XxxId: xxx.XxxId, NoXxx: xxx.NoXxx }) .subscribe( data => { console.log('[update] PATCH Request is successful |' + data + '|'); return data; }, error => { console.log('[update] Error |' + error + '|'); return error; }); } // update