Select a different version of angular when generating new project with angular cli

2

It may be a silly question, but the fact is that when generating a new project of angle with ng new miproyecto , version 6 of angular is installed by default.

Can I choose which version to use, for example if I want to install version 4?

    
asked by Michel Novellino 07.12.2018 в 20:13
source

1 answer

2

You doubt that you also have many Angular developers.

The answer is You can not change the version first .

To change the version you have to install a different version of the CLI specifying which one you want using the npm command

npm install -g @angular/cli@version

where version is one of the published versions of the cli

Keep in mind that generating components, services, executing commands, etc. from an existing project is not the same as creating a new one. If you have a global CLI and a local one in an existing project which will be used is the local .

This file on github is in the schematics which are the ones used to generate code and tells you the versions that are used in the latest release.

export const latestVersions = {
  // These versions should be kept up to date with latest Angular peer dependencies.
  Angular: '~7.1.0',
  RxJs: '~6.3.3',
  ZoneJs: '~0.8.26',
  TypeScript: '~3.1.6',
  TsLib: '^1.9.0',
  // The versions below must be manually updated when making a new devkit release.
  DevkitBuildAngular: '~0.12.0-beta.1',
  DevkitBuildNgPackagr: '~0.12.0-beta.1',
};

As you can see it is a code file that is executed when the CLI is going to generate a new project and therefore in your installation those numbers are harcoded. If you go to the installation of your npm global and search in this path <npm_install_path>\node_modules\@angular\cli\node_modules\@schematics\angular\utility\ you will find the same file. The global installation path of npm packages varies between operating systems, so I did not include it.

The solution can be

  • Install a smaller version of the global CLI
  • Generate your application
  • Refresh the global CLI
  • Run your application and commands using a smaller local CLI and a larger global

Remember that the CLI has been evolving over time so what I have said may not be true for some versions, especially the first ones.

    
answered by 07.12.2018 / 21:04
source