【发布时间】:2018-11-06 06:49:32
【问题描述】:
我使用 angular2 创建了一个 angular 通用应用程序,我在其中请求 /category 服务。
this.hsService.getCategories(AppConstants.BASE_URL_GET_CATGORIES).subscribe(
resp => {
if (resp !== null) {
console.log('response is not null');
}else {
console.log('response is null');
}
},
err => {
console.log('error');
that.categories = that.Categories();
}
);
但是我在错误下方得到了这个错误。但是不明白为什么?
ERROR 错误:通过服务器上的 Http 请求的 URL 必须是绝对的。 URL: /category at validateRequestUrl (D:\Myprojects\angular Universal\ciel\node_modules\@angular\platform-server\bundles\platform-server.umd.js:99:15 在新的 ZoneMacroTaskConnection (D:\Myprojects\angular 通用\ciel\node_modules\@angular\platform-server\bundles\platform-server.umd.js:226:9) 在 ZoneMacroTaskBackend.createConnection (D:\Myprojects\angular 通用\ciel\node_modules\@angular\platform-server\bundles\platform-server.umd.js:262:16) 在 httpRequest (D:\Myprojects\angular 通用\ciel\node_modules\@angular\http\bundles\http.umd.js:1833:20) 在 Http.request (D:\Myprojects\angular universal\ciel\node_modules\@angular\http\bundles\http.umd.js:1943:34) 在 Http.get (D:\Myprojects\angular universal\ciel\node_modules\@angular\http\bundles\http.umd.js:1957:21) 在 n.getCategories (D:\Myprojects\angular universal\ciel\dist-server\main.bundle.js:1:26301) 在 n.XV61.n.getCategories (D:\Myprojects\angular universal\ciel\dist-server\main.bundle.js:1:24428) 在 n.XV61.n.ngOnInit (D:\Myprojects\angular universal\ciel\dist-server\main.bundle.js:1:24346) 在 checkAndUpdateDirectiveInline (D:\Myprojects\angular universal\ciel\node_modules\@angular\core\bundles\core.umd.js:10875:19)
有人可以帮助我吗?
【问题讨论】:
-
该 API 中的 Http 请求似乎必须是完整格式的 URL,例如
http://www.someDomain.com/somePath。您似乎正在尝试向/category发出请求。显然你不能这样做。某处的某些代码必须包含协议和域。
标签: node.js angular angular-universal