Javascript 如何在我的项目中找到我的角度版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44502779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:34:30  来源:igfitidea点击:

how to find my angular version in my project?

javascriptangular

提问by Vignesh Kasthurisamy

I have setup the angular code on my local machine. I need to know the version of the angular that I am using in the project. how can I easily find it in cmd prompt?

我已经在本地机器上设置了角度代码。我需要知道我在项目中使用的角度的版本。如何在 cmd 提示符下轻松找到它?

回答by Mohamed Ali RACHID

try this command :

试试这个命令:

ng --version

It prints out Angular, Angular CLI, Node, Typescript versions etc.

它打印出 Angular、Angular CLI、Node、Typescript 版本等。

回答by Max Koretskyi

There are several ways you can do that:

有几种方法可以做到这一点:

  1. Go into node_modules/@angular/core/package.jsonand check versionfield.
  2. If you need to use it in your code, you can import it from the @angular/core:

    import { VERSION } from '@angular/core';

  3. Inspect the rendered DOM - Angular adds the version to the main component element:

    <my-app ng-version="4.1.3">

  1. 进入node_modules/@angular/core/package.json并检查version字段。
  2. 如果您需要在代码中使用它,可以从以下位置导入它@angular/core

    import { VERSION } from '@angular/core';

  3. 检查渲染的 DOM - Angular 将版本添加到主要组件元素:

    <my-app ng-version="4.1.3">

回答by Trilok Pathak

For Angular 1 or 2 (but not for Angular 4+):

对于 Angular 1 或 2(但不适用于 Angular 4+):

You can also open the consoleand go to the element tab on the developer tools of whatever browser you use.

您还可以打开控制台并转到您使用的任何浏览器的开发人员工具上的元素选项卡。

Or

或者

Type angular.version to access the Javascript object that holds angular version.

输入 angular.version 以访问保存 angular 版本的 Javascript 对象。

For Angular 4+ There is are the number of ways as listed below :

对于 Angular 4+,有以下几种方式:

Write below code in the command prompt/or in the terminal in the VS Code.

在命令提示符/或终端中的 VS Code 中编写以下代码。

  1. ng version or ng --version (See the attachment for the reference.)
  2. ng v
  3. ng -v
  1. ng version 或 ng --version(请参阅附件以获取参考。)
  2. ng -v

In the terminal you can find the angular version as shown in the attached image : enter image description here

在终端中,您可以找到如附图所示的 angular 版本: 在此处输入图片说明

  1. You can also open the consoleand go to the element tab on the developer tools of whatever browser you use. As displayed in the below image :
  1. 您还可以打开控制台并转到您使用的任何浏览器的开发人员工具上的元素选项卡。如下图所示:

enter image description here

在此处输入图片说明

5.Find the package.json file, You will find all the installed packages and their version.

5.找到 package.json 文件,你会找到所有安装的包和它们的版本。

回答by Virendra Jadeja

define VERSION variable and import version into it.

定义 VERSION 变量并将版本导入其中。

import { VERSION } from '@angular/core';

Now you can use VERSION variable in your code to print version For example,

现在您可以在代码中使用 VERSION 变量来打印版本例如,

console.log(VERSION.full); 

回答by Nateowami

For Angular 2+ you can run this in the console:

对于 Angular 2+,您可以在控制台中运行:

document.querySelector('[ng-version]').getAttribute('ng-version')

For AngularJS 1.x:

对于 AngularJS 1.x:

angular.version.full

回答by R M Shahidul Islam Shahed

  1. Browser > Inspect > Element >

    <.app-root _nghost-hey-c0="" ng-version="8.2.11">

  2. In terminal

    :> ng version
    :> ng --version
    :> ng -v

  1. 浏览器 > 检查 > 元素 >

    <.app-root _nghost-hey-c0="" ng-version="8.2.11">

  2. 在终端

    :> ng 版本
    :> ng --version
    :> ng -v

回答by Eduard Florinescu

If you try to check angular version in the browser, for me only this worked Ctrl+Shift+iand paste below command in console:

如果您尝试在浏览器中检查 angular 版本,对我来说只有这有效Ctrl+ Shift+i并在控制台中粘贴以下命令:

document.querySelector('[ng-version]').getAttribute('ng-version')

ex:

前任:

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

回答by minitechi

you can use ng --versionfor angular version 7

您可以将ng --version用于角度版本 7