Anglarjs2 - Http get request : Error: unable to parse url ..original error: Cannot read property 'split' of undefined in [null]

纵饮孤独 提交于 2019-12-23 12:35:58

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!