简体   繁体   English

在ionic 2中导入angular2 / http具有错误“找不到模块”

[英]importing angular2/http in ionic 2 has error “cannot find module”

I'm started learning ionic 2 and I have a problem with importing dependency in my app.ts file. 我开始学习ionic 2,并且在我的app.ts文件中导入依赖项时遇到问题。

when i want use: 当我想使用时:

"import {Http} from "angular2/http";

its show me, error with this subject: 它告诉我,这个问题的错误:

[ts] cannot find module 'angular2/http'.

this is my package.json's content: 这是我的package.json的内容:

"dependencies": {
"@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",
"es6-shim": "^0.35.0",
"ionic-angular": "2.0.0-beta.7",
"ionic-native": "^1.1.0",
"ionicons": "3.0.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12"
}

ok, i found a solution, 好的,我找到了解决方案,

in Ionic 2, Beta 7, we should use: 在Ionic 2,Beta 7中,我们应该使用:

import {Http} from '@angular/http'; 从'@ angular / http'导入{Http};

Just in case if this could be useful to someone, there are some other changes you would need to do in order to upgrade to Ionic 2 beta 7 (or beta 8 now). 以防万一这可能对某人有用,为了升级到Ionic 2 beta 7 (或现在的beta 8),您还需要做一些其他更改。

You can take a look at the recommended steps (and breaking changes like that one) here . 您可以在此处查看建议的步骤(以及类似的重大更改 )。

========= =========

EDIT: 编辑:

As Bond - Java Bond suggests, these are the breaking changes in case of the link goes dead: 正如Bond-Java Bond所建议的,这些是链接失效时的重大更改:

2.0.0-beta.7 (2016-05-19) BREAKING CHANGES 2.0.0-beta.7(2016-05-19)更改

Angular Update to 2.0.0-rc.1 角更新到2.0.0-rc.1

Angular has been updated to 2.0.0-rc.1, follow these steps to update Angular. Angular已更新为2.0.0-rc.1,请按照以下步骤更新Angular。

  1. Edit your package.json and remove the angular2 entry: 编辑您的package.json并删除angular2条目:

     "angular2": "2.0.0-beta.15" 
  2. Then, run the following command from a terminal to update Ionic and Angular, or take a look at the starter's package.json changes and update each version: 然后,从终端运行以下命令以更新Ionic和Angular,或查看启动程序的package.json更改并更新每个版本:

     npm install --save ionic-angular@2.0.0-beta.7 @angular/core @angular/compiler @angular/common @angular/platform-browser @angular/platform-browser-dynamic @angular/router @angular/http rxjs@5.0.0-beta.6 zone.js@0.6.12 reflect-metadata 
  3. Run the following command from a terminal to update the gulp task for ionic-gulp-scripts-copy : 从终端运行以下命令以更新ionic-gulp-scripts-copy的gulp任务:

     npm install --save-dev ionic-gulp-scripts-copy@2.0.0 
  4. Then, change any imports in your application from angular2 to @angular . 然后,将应用程序中的所有导入从angular2@angular For example, the following. 例如,以下。

     import {ViewChild} from 'angular2/core'; import {Http} from 'angular2/http'; 

    becomes 变成

     import {ViewChild} from '@angular/core'; import {Http} from '@angular/http'; 
  5. Remove the import for angular2-polyfills in index.html : index.html删除angular2-polyfills的导入:

     <script src="build/js/angular2-polyfills.js"></script> 

    and replace it with the following scripts: 并将其替换为以下脚本:

     <script src="build/js/zone.js"></script> <script src="build/js/Reflect.js"></script> 
  6. Replace all template variables in ngFor with let . let替换ngFor所有模板变量。 For example: 例如:

     *ngFor="#session of group.sessions" 

    becomes 变成

     *ngFor="let session of group.sessions" 
  7. Replace all template variables in virtualScroll . 替换virtualScroll所有模板变量。 For example: 例如:

     *virtualItem="#item" 

    becomes 变成

     *virtualItem="let item" 
  8. View the Angular Changelog for more in depth changes. 查看Angular Changelog了解更多深度更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM