如何使用angular-cli而不是angular 4创建角度2 app?
https://github.com/angular/angular-cli
我的package.json:
"dependencies": {
"@angular/animations": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "1.1.1",
"@angular/compiler-cli": "^4.0.0",
"@angular/language-service": "^4.0.0",
"@types/jasmine": "2.5.45",
"@types/node": "~6.0.60",
"codelyzer": "~3.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^1.2.1",
"protractor": "~5.1.2",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
我试图更改角度版本,但它仍然无法正常工作
答案 0 :(得分:3)
在你的package.json中 - > dependencies数组将角度版本更改为2.4.1并重建项目。
详细答案: -
1)使用Cli创建新项目。
ng new my-newapp
2)将目录更改为
cd my-newapp
3)更新package.json - >依赖。将角度版本更改为2.4.1并将路由器更改为3.4.1
示例: -
{
"name": "my-newapp",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "2.4.1",
"@angular/compiler": "2.4.1",
"@angular/compiler-cli": "2.4.1",
"@angular/core": "2.4.1",
"@angular/forms": "2.4.1",
"@angular/http": "2.4.1",
"@angular/platform-browser": "2.4.1",
"@angular/platform-browser-dynamic": "2.4.1",
"@angular/router": "3.4.1",
"@angular/upgrade": "2.4.1",
"@angular/material": "2.0.0-beta.0",
"bootstrap": "^3.3.7",
"concurrently": "^3.1.0",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"reflect-metadata": "^0.1.9",
"rxjs": "^5.0.2",
"systemjs": "^0.19.41",
"zone.js": "^0.7.4"
},
"devDependencies": {
"@angular/cli": "1.0.0",
"@angular/compiler-cli": "^4.0.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0"
}
}
4)重新安装所有软件包(可选: - 在执行此命令之前,您可以删除node-module文件夹)
npm install
5)启动浏览器
ng serve
注意: - 在执行ng服务时,我的系统面临问题
ERROR in AppModule is not an NgModule
您通过向app.module.ts添加空行来解决此问题。