2016-11-15 260 views
1

我必須做出登錄頁面,但在我做之前,我嘗試用簡單的HTTP獲取JSON對象。但頁面沒有在一些文章中,我讀加載 enter image description hereAngular2,HTTP請求

的arror (index):18 Error: (SystemJS) XHR error (404 Not Found) loading可如果我的index.html這一行

<script src="node_modules/angular2/bundles/http.dev.js"></script>

寫來解決,但它確實不加載。我試圖

<script src="node_modules/@angular/bundles/http.dev.js"></script>

但沒有任何幫助。在我進口我有@angular代替angular2

票數是我的package.json

{ 
 
    "name": "angular-quickstart", 
 
    "version": "1.0.0", 
 
    "scripts": { 
 
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ", 
 
    "lite": "lite-server", 
 
    "tsc": "tsc", 
 
    "tsc:w": "tsc -w" 
 
    }, 
 
    "licenses": [ 
 
    { 
 
     "type": "MIT", 
 
     "url": "https://github.com/angular/angular.io/blob/master/LICENSE" 
 
    } 
 
    ], 
 
    "dependencies": { 
 
    "@angular/common": "~2.2.0", 
 
    "@angular/compiler": "~2.2.0", 
 
    "@angular/core": "~2.2.0", 
 
    "@angular/forms": "~2.2.0", 
 
    "@angular/http": "~2.2.0", 
 
    "@angular/platform-browser": "~2.2.0", 
 
    "@angular/platform-browser-dynamic": "~2.2.0", 
 
    "@angular/router": "~3.2.0", 
 
    "@angular/upgrade": "~2.2.0", 
 
    "angular-in-memory-web-api": "~0.1.15", 
 
    "core-js": "^2.4.1", 
 
    "reflect-metadata": "^0.1.8", 
 
    "rxjs": "5.0.0-beta.12", 
 
    "systemjs": "0.19.39", 
 
    "zone.js": "^0.6.25" 
 
    }, 
 
    "devDependencies": { 
 
    "@types/core-js": "^0.9.34", 
 
    "@types/node": "^6.0.45", 
 
    "concurrently": "^3.0.0", 
 
    "lite-server": "^2.2.2", 
 
    "typescript": "^2.0.3" 
 
    } 
 
}

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

感謝很多的幫助

+0

你會不得不張貼一些更多的代碼。 –

+0

'node_modules'下有'@ angular'嗎? –

+0

你可以發佈你的'packages.json'嗎?你運行了'npm install'嗎? –

回答

0

您需要將HttpModule導入您的模塊。

app.module.ts

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

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