我正在尝试使用 Angular 2 和 Typescript 发出一个简单的 HTTP GET 请求。我收到 404 错误,网址为空。下面显示的是我的组件文件以及我收到的错误。
\n\nimport { Component, OnInit } from \'@angular/core\';\nimport { Router } from \'@angular/router\';\nimport { BreadcrumbService } from \'./breadcrumbService\';\nimport { Http, Response } from \'@angular/http\';\n\n@Component({\n moduleId: module.id,\n providers: [ BreadcrumbService],\n templateUrl: \'html/appList.html\',\n styleUrls: [\'css/list.css\']\n\n})\nexport class HealthComponent {\n constructor(private http: Http) {\n this.http.get(\'http://jsonplaceholder.typicode.com/posts/1\')\n .toPromise()\n .then((res: Response) => {\n console.log(\'RES: \', res);\n })\n .catch((err: Error) => {\n console.log(\'ERR!!: \', err);\n });\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n错误信息:
\n\nResponse {_body: Object, status: 404, ok: false, …Run Code Online (Sandbox Code Playgroud) 我在 Rails 表单上有一个复选框,如下所示:
.columns.small-1
= f.label :private
= f.check_box :private
Run Code Online (Sandbox Code Playgroud)
如果未选中该框,则表单将正确发送并传递一个值。如果选中该框,则表单会发送相同的字段两次,一次值为 0,一次为 1,这导致该框始终显示为“未选中”并且值为 0。一直在研究 Rails 中的隐藏字段,但不确定如何来应用到这个问题。