问题
How can i create angular 2 app with angular-cli instead of angular 4?
https://github.com/angular/angular-cli
my 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"
}
i tried to change the angular version but it still doesn't work
回答1:
In your package.json -> dependencies array change angular version to 2.4.1 and rebuild your project.
Detail answer :-
1) Create new project using Cli.
ng new my-newapp
2) change directory to
cd my-newapp
3) update package.json -> dependencies. Change angular version to 2.4.1 and change router to 3.4.1
example:-
{
"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) reinstall all package ( optional:- before execute this command you can delete node-module folder)
npm install
5) launch browser
ng serve
Note :- In my system while execute ng serve i faced issue
ERROR in AppModule is not an NgModule
you fix this issue by adding an empty line to the app.module.ts.
来源:https://stackoverflow.com/questions/44552009/use-angular-2-instead-of-angular-4-with-angular-cli