Anglarjs2-Http获取请求:错误:无法解析URL ..原始错误:无法读取[null]中未定义的属性"split" [英] Anglarjs2 - Http get request : Error: unable to parse url ..original error: Cannot read property 'split' of undefined in [null]
问题描述
当我在Hero.service.ts中使用get Url作为Web api时,在浏览器控制台中出现以下错误.但是,当我在那个项目中使用.Json文件时,它工作正常,因为我能够在输出页面中看到值.我只是在学习angular.io网站.
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.
以下是控制台中的错误:
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
这是整个代码可用,
请问我在这方面做错什么了吗?
Could you please help me what i'm doing wrong in this?
推荐答案
您的问题来自InMemoryBackendService
,它需要以下URL格式(路径分为两个级别):
You problem comes from the InMemoryBackendService
which expects the following URL format (two levels for path):
http://host:port/base/collectionName
在您的情况下,该服务会引发异常,因为`collectionName未定义...
In your case, the service throws an exception because `collectionName is undefined...
要使其正常工作,请使用遵循此格式的URL,或者从提供程序中删除InMemoryBackendService
类:
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 }), // <---
这篇关于Anglarjs2-Http获取请求:错误:无法解析URL ..原始错误:无法读取[null]中未定义的属性"split"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!