【问题标题】:configure angular2 http in packages.json在 packages.json 中配置 angular2 http
【发布时间】:2016-07-21 05:03:25
【问题描述】:

我正在尝试用 Angular 2 编写一个非常简单的应用程序 我需要读取 JSON 文件,因此需要 angular2/http

应用npm init 构建packages.json 文件:

{
  "name": "front-end",
  "version": "1.0.0",
  "description": " blah blah",
  "main": "gulpfile.js",
  "dependencies": {
    "connect": "^3.4.1",
    "del": "^1.2.1",
    "angular2": "2.0.0-beta.16",
    "gulp": "^3.9.1",
    "gulp-typescript": "^2.13.0",
    "open": "^0.0.5",
    "reflect-metadata": "^0.1.2",
    "serve-static": "^1.10.2",
    "systemjs": "^0.19.27",
    "zone.js": "^0.6.12",
    "rxjs": "5.0.0-beta.2"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "www.hello.com"
  },
  "author": "kpmg-dna-fs-de",
  "license": "ISC"
}

我得到以下信息:

错误:错误:XHR 错误 (404 Not Found) loading http://localhost:9000/angular2/http.js(...)

来自 angula2.polyfills。不知道如何进行。 auth0 演示 here 表明不需要在依赖项中明确提及 angular2/http。

跟使用有什么区别:

"@angular/common":  "2.0.0-rc.1",
"@angular/compiler":  "2.0.0-rc.1",
"@angular/core":  "2.0.0-rc.1",
"@angular/http":  "2.0.0-rc.1",
"@angular/platform-browser":  "2.0.0-rc.1",
"@angular/platform-browser-dynamic":  "2.0.0-rc.1",
"@angular/router":  "2.0.0-rc.1",
"@angular/router-deprecated":  "2.0.0-rc.1",
"@angular/upgrade":  "2.0.0-rc.1",

here 我的意思是:我得到了版本号,但为什么 "angular2": "2.0.0-rc.1" 不能与 npm install 一起使用?

【问题讨论】:

    标签: http types angular


    【解决方案1】:

    请查看使用 Angular 2 应用程序的 Angular CLI 方式,它提供了结构良好的开发方式。

    Angular 2 模块使用 system.js 加载,如您提到的快速入门或 CLI。

    如何从你的问题中得出以下几点。

    1. 想要构建 Angular 2 应用程序 - 请点击快速入门链接或更好地使用 Angular CLI

    2. 想使用 HTTP 方式访问数据 -- 使用 angular2-in-memory-web-api,使用它可以从 JSON 文件加载数据并使用 Angular 2 HTTP 概念将此数据传递给 UI。

    【讨论】:

      猜你喜欢
      • 2016-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-15
      • 1970-01-01
      • 2016-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多