AngularJS安装版本问题

本文介绍了如何在Node.js版本不满足AngularCLI要求时,通过降低CLI版本来解决创建Angular项目的问题,包括安装特定版本的CLI、创建新项目以及运行项目的步骤。
摘要由CSDN通过智能技术生成

一、安装

        Angular CLI 脚手架安装命令:

npm install -g @angular/cli

        在安装前请确保自己安装NodeJS环境版本为V18及以上,否则会因node版本问题导致项目无法正常运行。

        脚手架安装后,已提示了当前node版本必须为18.13.0或大于20.9.0版本:

        在node版本不一致情况下,创建项目会提示Node.js版本必须为v18.13,如下图:

      

二、匹配版本

        本人电脑上使用的node版本为v16,在不升级node版本情况下,可以考虑降低@angular/cli版本,地址:Releases · angular/angular-cli · GitHub

        2.1 安装命令

        在Releases中找到对应版本进行安装,命令如下:

npm install -g @angular/cli@16.2.6

        此时则没有版本问题提示了,如下图:

        2.2 创建项目

D:\workspace\web\angular>ng new hello-world
? Would you like to share pseudonymous usage data about this project with the Angular Team
at Google under Google's Privacy Policy at https://policies.google.com/privacy. For more
details and how to change this setting, see https://angular.io/analytics. Yes

Thank you for sharing pseudonymous usage data. Should you change your mind, the following
command will disable this feature entirely:

    ng analytics disable --global

Global setting: enabled
Local setting: No local workspace configuration file.
Effective status: enabled
? Would you like to add Angular routing? Yes
? Which stylesheet format would you like to use? SCSS   [ https://sass-lang.com/documentation/syntax#scss
 ]
CREATE hello-world/angular.json (2899 bytes)
CREATE hello-world/package.json (1042 bytes)
CREATE hello-world/README.md (1064 bytes)
CREATE hello-world/tsconfig.json (901 bytes)
CREATE hello-world/.editorconfig (274 bytes)
CREATE hello-world/.gitignore (548 bytes)
CREATE hello-world/tsconfig.app.json (263 bytes)
CREATE hello-world/tsconfig.spec.json (273 bytes)
CREATE hello-world/.vscode/extensions.json (130 bytes)
CREATE hello-world/.vscode/launch.json (470 bytes)
CREATE hello-world/.vscode/tasks.json (938 bytes)
CREATE hello-world/src/main.ts (214 bytes)
CREATE hello-world/src/favicon.ico (948 bytes)
CREATE hello-world/src/index.html (296 bytes)
CREATE hello-world/src/styles.scss (80 bytes)
CREATE hello-world/src/app/app-routing.module.ts (245 bytes)
CREATE hello-world/src/app/app.module.ts (393 bytes)
CREATE hello-world/src/app/app.component.html (23115 bytes)
CREATE hello-world/src/app/app.component.spec.ts (1006 bytes)
CREATE hello-world/src/app/app.component.ts (216 bytes)
CREATE hello-world/src/app/app.component.scss (0 bytes)
CREATE hello-world/src/assets/.gitkeep (0 bytes)
√ Packages installed successfully.
warning: LF will be replaced by CRLF in .editorconfig.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .vscode/extensions.json.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .vscode/launch.json.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .vscode/tasks.json.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in angular.json.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in package-lock.json.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in package.json.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/app/app-routing.module.ts.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/app/app.component.html.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/app/app.component.spec.ts.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/app/app.component.ts.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/app/app.module.ts.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/index.html.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/main.ts.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/styles.scss.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in tsconfig.app.json.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in tsconfig.json.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in tsconfig.spec.json.
The file will have its original line endings in your working directory
    Successfully initialized git.

       2.3 运行项目

        选择项目目录:

D:\workspace\web\angular>cd hello-world

        运行hello-world项目命令如下:

D:\workspace\web\angular\hello-world>ng serve --open
? Would you like to share pseudonymous usage data about this project with the Angular Team
at Google under Google's Privacy Policy at https://policies.google.com/privacy. For more
details and how to change this setting, see https://angular.io/analytics. Yes

Thank you for sharing pseudonymous usage data. Should you change your mind, the following
command will disable this feature entirely:

    ng analytics disable

Global setting: enabled
Local setting: enabled
Effective status: enabled
√ Browser application bundle generation complete.

Initial Chunk Files   | Names         |  Raw Size
vendor.js             | vendor        |   2.35 MB |
polyfills.js          | polyfills     | 333.17 kB |
styles.css, styles.js | styles        | 230.92 kB |
main.js               | main          |  48.74 kB |
runtime.js            | runtime       |   6.52 kB |

                      | Initial Total |   2.96 MB

Build at: 2024-02-26T08:05:28.353Z - Hash: daa545468f767600 - Time: 33009ms

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **


√ Compiled successfully.

        运行结果下图:

        如上图,项目可以正常运行了。

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
AngularJS 是一种基于 JavaScript前端框架,它提供了一种基于 MVC(Model-View-Controller)的开发模式,让开发者可以更加轻松地构建动态、交互性强的 Web 应用程序。以下是 AngularJS 入门的一些步骤: 1. 学习基础的 HTML、CSS 和 JavaScriptAngularJS 是基于 JavaScript 的框架,因此需要先掌握基础的 HTML、CSS 和 JavaScript 知识。 2. 学习 AngularJS 的基本概念和术语。AngularJS 的核心概念包括模块、控制器、作用域、表达式、指令、服务等等,需要了解这些概念和术语的含义和作用。 3. 下载和安装 AngularJS。可以从 AngularJS 的官方网站上下载 AngularJS 的最新版本,并按照官方文档中的说明进行安装。 4. 创建你的第一个 AngularJS 应用程序。可以从官方文档中的入门教程开始,创建一个简单的 AngularJS 应用程序,并逐步学习如何使用 AngularJS 的各种功能和特性。 5. 学习 AngularJS 的进阶特性。除了基本的概念和功能外,AngularJS 还提供了很多进阶特性,例如路由、依赖注入、动画等等,可以通过官方文档和其他学习资源深入学习这些特性。 6. 参与社区和其他开发者的讨论和交流。AngularJS 拥有一个庞大的社区和开发者群体,可以通过参与讨论和交流,了解最新的开发动态和技术趋势,提高自己的技术水平。 希望这些步骤能够帮助你快速入门 AngularJS,并能够使用 AngularJS 开发出优秀的 Web 应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值