简体   繁体   English

我怎么知道我使用哪个角度2版本?

[英]How can I know which angular 2 version Im using?

In the browser's developer console with angular 1 I used to type: 在浏览器的开发者控制台中,角度为1,我曾经输入:

angular.version.full

But do not work for angular 2. 但是不要为角2工作。

Agree Kévin Lemele. 同意KévinLemele。

The other way is the root component in your html has a attribute of ng-version . 另一种方式是你的html中的root组件有一个ng-version属性。 Like this. 像这样。

<app ng-version="2.3.0"></app>

if you have the angular cli, you can do ng --version which will return something along the lines of: 如果你有角度cli,你可以做ng --version ,它将返回以下内容:

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.2.0
node: 8.1.3
os: darwin x64
@angular/animations: 4.2.5
@angular/common: 4.2.5
@angular/compiler: 4.2.5
@angular/core: 4.2.5
@angular/forms: 4.2.5
@angular/http: 4.2.5
@angular/material: 2.0.0-beta.7
@angular/platform-browser: 4.2.5
@angular/platform-browser-dynamic: 4.2.5
@angular/router: 4.2.5
@angular/cli: 1.2.0
@angular/compiler-cli: 4.2.5
@angular/language-service: 4.2.5

you can see in packages.json your angular version. 你可以在packages.json中看到你的角度版本。

"@angular/common": "2.3.1",
"@angular/compiler": "2.3.1",
"@angular/core": "2.3.1",
"@angular/forms": "2.3.1",
"@angular/http": "2.3.1",
"@angular/platform-browser": "2.3.1",
"@angular/platform-browser-dynamic": "2.3.1",
"@angular/router": "3.3.1"

if you have ^ before the version and run npm install command so you have the last angular 2 version. 如果你在版本之前有^并运行npm install命令,那么你有最后的角度2版本。

You can import the version of angular like this: 您可以像这样导入角度的版本:

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

See this issue 看到这个问题

The following piece of code works well: 以下代码很有效:

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

@Component({
  selector: 'angular-version',
  template: `Version: {{version.full}}`

})
export class AngularVersionComponent {
   version = VERSION
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM