How do I create new project with the latest Angular 4 release using Angular CLI with the command below :
ng new new_project
I have the following versions installed
- @angular/cli: 1.0.0-rc.2
- node: 7.7.3
- npm: 4.4.1
You cannot create a new Angular application with the CLI that uses Angular 4 out of the box. At least, not at the moment. Only Angular 2 is supported by the CLI, at this time. I imagine that will change soon enough.
However, you can create a new application using ng new <app-name>, and then change the version of Angular it uses in the package.json. Run npm install, and it should all work. That has been my experience.
Hope this helps you out.
UPDATE:
I am mistaken! There is an option that you can pass to the ng new command that will set up the project to use ng 4.
ng new project_new --ng4
From ng --help:
--ng4 (Boolean) (Default: false) Create a project with Angular 4 in the template.
Right now this sets up the @angular section package.json as follows.
"dependencies": {
"@angular/common": ">=4.0.0-beta <5.0.0",
"@angular/compiler": ">=4.0.0-beta <5.0.0",
"@angular/core": ">=4.0.0-beta <5.0.0",
"@angular/forms": ">=4.0.0-beta <5.0.0",
"@angular/http": ">=4.0.0-beta <5.0.0",
"@angular/platform-browser": ">=4.0.0-beta <5.0.0",
"@angular/platform-browser-dynamic": ">=4.0.0-beta <5.0.0",
"@angular/router": ">=4.0.0-beta <5.0.0",
...
Just tried it, and it works.
UPDATE 2
The --ng4 option has now been removed as the latest CLI will now create an Angular 5 project just by using ng new project_name.
The easiest way to create an Angular 4 project using Angular CLI is install an older version of the @angular/cli (1.4.10)
npx @angular/cli@1.4.10 new myangular4
(thanks Explosion Pills)
Or
> npm remove -g @angular/cli
> npm install -g @angular/cli@1.4.10
> ng --version
@angular/cli: 1.4.10
> ng new myangular4
Creates a myangular4/package.json
{
"name": "myangular4",
"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/animations": "^4.2.4",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"core-js": "^2.4.1",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
To create an Angular_4 project using Angular CLI follow these commands lines :
npm remove -g @angular/cli
npm install -g @angular/cli@1.4.10
ng new myNewAngular4App