I'm started learning ionic 2 and I have a problem with importing dependency in my app.ts file.
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:
"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:
import {Http} from '@angular/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).
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:
2.0.0-beta.7 (2016-05-19) BREAKING CHANGES
Angular Update to 2.0.0-rc.1
Angular has been updated to 2.0.0-rc.1, follow these steps to update Angular.
Edit your package.json
and remove the angular2
entry:
"angular2": "2.0.0-beta.15"
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:
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
Run the following command from a terminal to update the gulp task for ionic-gulp-scripts-copy
:
npm install --save-dev ionic-gulp-scripts-copy@2.0.0
Then, change any imports in your application from angular2
to @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';
Remove the import for angular2-polyfills
in index.html
:
<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>
Replace all template variables in ngFor
with let
. For example:
*ngFor="#session of group.sessions"
becomes
*ngFor="let session of group.sessions"
Replace all template variables in virtualScroll
. For example:
*virtualItem="#item"
becomes
*virtualItem="let item"
View the Angular Changelog for more in depth changes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.