Angular2,HTTP请求

时间:2016-11-15 22:54:50

标签: angular

我必须创建Login Page,但在我做之前,我尝试使用简单的HTTP get with JSON对象。但该页面无法加载 enter image description here

在一些帖子中我读到如果我在index.html中写这行就可以解决#{1}}



(index):18 Error: (SystemJS) XHR error (404 Not Found) loading




,但它没有加载。我试过了



<script src="node_modules/angular2/bundles/http.dev.js"></script>
&#13;
&#13;
&#13;

但没有任何帮助。在我的导入中,我有@angular stead angular2

hier是我的package.json

&#13;
&#13;
<script src="node_modules/@angular/bundles/http.dev.js"></script>
&#13;
&#13;
&#13;

和我的代码 https://gist.github.com/anonymous/d3b5f00ed5e9a5d3db603bf6eafb402fhttps://gist.github.com/anonymous/d6940887480a6501a539fa15f8de6b9f

非常感谢你的帮助

1 个答案:

答案 0 :(得分:0)

您需要将HttpModule导入模块。

<强> app.module.ts

import { HttpModule } from '@angular/http'; // add this line

@NgModule({
    imports: [
       //....
       HttpModule //make sure you import `HttpModule` into `NgModule`
    ],
    // ...
)}