问题
Getting below error in browser console, when I'm using get Url as web api in Hero.service.ts. But It's working fine when I used with .Json file with in a that project as I'm able to see the values in output page. I'm just learning with angular.io website.
Below is the error in the console:
angular2-polyfills.js:471 Error: Uncaught (in promise): EXCEPTION: Error: unable to parse url 'http://md5.jsontest.com/?text=example_text'; original error: Cannot read property 'split' of undefined in [null](…)consoleError @ angular2-polyfills.js:471
Get url: http://md5.jsontest.com/?text=example_text
Here is that entire code available,
Plunker
Could you please help me what i'm doing wrong in this?
回答1:
You problem comes from the InMemoryBackendService
which expects the following URL format (two levels for path):
http://host:port/base/collectionName
In your case, the service throws an exception because `collectionName is undefined...
To make it work either you use URLs that follow this format either you remove the InMemoryBackendService
class from the providers:
providers: [
HTTP_PROVIDERS,
HeroService,
// in-memory web api providers
provide(XHRBackend, { useClass: InMemoryBackendService }), // <---
来源:https://stackoverflow.com/questions/36628496/anglarjs2-http-get-request-error-unable-to-parse-url-original-error-cann