Logging in console always show null when user angular httpCliend
See original GitHub issueI user HttpClient of angular9 to call mock mirage js but in console tab it always show null but actually I got response. this is my code.
Angular code
this.http.get('api/business-type').subscribe((res) => {
console.log(res);
});
Mirage js code
import * as businessType from './mockFile/BusnessType.json';
export function mockServer() {
return new Server({
routes() {
this.passthrough();
this.namespace = "api";
this.get('/business-type', () => businessType.default); // JSON Object
},
})
};
console
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
HttpClient get return always null for any rest API - Stack Overflow
It always returns undefined (and not null), because your method doesn't return anything. Add return before this.http.get(... . And remove the ...
Read more >NgModel - Angular
This directive is used by itself or as part of a larger form. Use the ngModel selector to activate it. It accepts a...
Read more >FormControl - Angular
This argument always implicitly includes null because the control can be reset. To change this behavior, set nonNullable or see the usage notes...
Read more >Router - Angular
How to handle a navigation request to the current URL. One of: 'ignore' : The router ignores the request. 'reload' : The router...
Read more >Communicating with backend services using HTTP - Angular
The HttpClient service makes use of observables for all transactions. You must import the RxJS observable and operator symbols that appear in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Jesniphat You can see a Mirage.js with Angular 9 implementation here: https://github.com/zoltan-nz/hello-angular/tree/master/mirage
Hope it gives you a few ideas.
Oh, looks like we already have an issue for this one: https://github.com/miragejs/miragejs/issues/329
I’m going to close this issue and use #329 as the tracking issue.