使用Angular版本4启动一个新的Ionic 3项目

时间:2018-11-03 11:47:00

标签: angular ionic-framework ionic3

我已经安装了支持Angular 4.0.1的Ionic 3.6,因为我想重用一些我已经为桌面应用开发的代码。 我面临的问题是,当我使用

创建一个新项目时
ionic start newProject

它使用Angular 5,如您在下面的package.json中所见,在那里您还可以看到angular-ionic 3.9.2是依赖项。

如何使用Angular 4.0.1创建新项目?这也很重要,因为当我使用 ionic cordova运行android 测试项目然后编辑文件时,连接会因错误而中断。

谢谢。

{
  "name": "my5thproject",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "5.0.0",
    "@angular/compiler": "5.0.0",
    "@angular/compiler-cli": "5.0.0",
    "@angular/core": "5.0.0",
    "@angular/forms": "5.0.0",
    "@angular/http": "5.0.0",
    "@angular/platform-browser": "5.0.0",
    "@angular/platform-browser-dynamic": "5.0.0",
    "@ionic-native/core": "4.3.2",
    "@ionic-native/splash-screen": "4.3.2",
    "@ionic-native/status-bar": "4.3.2",
    "@ionic/storage": "2.1.3",
    "ionic-angular": "3.9.2",
    "ionicons": "3.0.0",
    "rxjs": "5.5.2",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.1.0",
    "@ionic/cli-plugin-ionic-angular": "1.4.1",
    "ionic": "3.6.0",
    "typescript": "2.4.2"
  },
  "description": "An Ionic project"
}

2 个答案:

答案 0 :(得分:1)

受Suresh答案的启发,最终的解决方案涉及不同的步骤:

  • 更改了package.json(我将其附加在答案的末尾)
    • 使用Angular 4.1.3,它是离子3.6.0的正确选择,对我的项目来说很好
    • 也将rxjs更改为5.4.0
    • 还将zone.js也更改为0.8.12
    • 还将打字稿更改为2.3.4
  • 已删除 node_modules 文件夹
  • 在项目内部启动npm install
  • 安装了rxjs和zone.js
    • npm install rxjs@5.4.0
    • npm install zone.js@0.8.12
  • 安装了正确版本的Cordova以防止发生错误
    • npm install --save-dev @ionic/cli-plugin-cordova@1.4.1
  • 在下一行中将config.xml中的minSdkVersion更改为19,以防止发生另一个错误
    • <preference name="android-minSdkVersion" value="19" />
  • 然后我得到了这个“ throw er; // Unhandled 'error' event”,我用命令解决了
    • npm i -D -E ws@3.3.2

这是一段漫长的旅程,但我终于做到了。也感谢关于SO的许多其他答案。知道是否有更直接的解决方案将很有趣。

package.json

{
  "name": "my5thproject",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "4.1.3",
    "@angular/compiler": "4.1.3",
    "@angular/compiler-cli": "4.1.3",
    "@angular/core": "4.1.3",
    "@angular/forms": "4.1.3",
    "@angular/http": "4.1.3",
    "@angular/platform-browser": "4.1.3",
    "@angular/platform-browser-dynamic": "4.1.3",
    "@ionic-native/core": "4.3.2",
    "@ionic-native/splash-screen": "4.3.2",
    "@ionic-native/status-bar": "4.3.2",
    "@ionic/storage": "2.1.3",
    "ajv": "^6.5.5",
    "cordova-android": "7.1.1",
    "cordova-plugin-device": "^1.1.4",
    "cordova-plugin-ionic-webview": "^1.2.1",
    "cordova-plugin-splashscreen": "^4.0.3",
    "cordova-plugin-whitelist": "^1.3.1",
    "ionic-angular": "3.6.0",
    "ionic-plugin-keyboard": "^2.2.1",
    "ionicons": "3.0.0",
    "rxjs": "^5.4.0",
    "sw-toolbox": "3.6.0",
    "zone.js": "^0.8.12"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.1.0",
    "@ionic/cli-plugin-cordova": "^1.4.1",
    "@ionic/cli-plugin-ionic-angular": "1.4.1",
    "ionic": "3.6.0",
    "typescript": "2.3.4",
    "ws": "3.3.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "ionic-plugin-keyboard": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {}
    },
    "platforms": [
      "android"
    ]
  }
}

答案 1 :(得分:0)

您应该使用3的最新版本,即3.9.2,它将具有性能和错误修复。您为3.6编写的代码应适用于3.9.1。请尝试将其集成。如果仍然要使用特定版本。您可以手动更新package.json文件。

{
  "name": "my5thproject",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "4.0.1",
    "@angular/compiler": "4.0.1",
    "@angular/compiler-cli": "4.0.1",
    "@angular/core": "4.0.1",
    "@angular/forms": "4.0.1",
    "@angular/http": "4.0.1",
    "@angular/platform-browser": "4.0.1",
    "@angular/platform-browser-dynamic": "4.0.1",
    "@ionic-native/core": "4.3.2",
    "@ionic-native/splash-screen": "4.3.2",
    "@ionic-native/status-bar": "4.3.2",
    "@ionic/storage": "2.1.3",
    "ionic-angular": "3.6.0",
    "ionicons": "3.0.0",
    "rxjs": "5.5.2",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.1.0",
    "@ionic/cli-plugin-ionic-angular": "1.4.1",
    "ionic": "3.6.0",
    "typescript": "2.4.2"
  },
  "description": "An Ionic project"
}

更新package.json之后。尝试删除node_modules文件夹并运行'npm install'。