CESCO
CESCO

Reputation: 7768

How to check Angular2 version with typescript

I have written a simple app with [email protected], and it works great. Now that I am testing it with the latest version of the alpha and beta avaible on npm, and I keep wondering if I really really changed or I am caching something.

I want to do something like the below on my root component

export class ChromeComponent {

  ngOnInit() {
    console.log('angular version');
  }
}

angular.version on the console return undefined

Upvotes: 25

Views: 26004

Answers (4)

Lucas
Lucas

Reputation: 10313

New answer since accepted one no longer the case on stable angular releases, easiest way to check angular version is to do so with npm list command at project root:

npm list  @angular/core

Just in case you can check following as well, versions should match:

npm list @angular/common

npm list @angular/compiler

Upvotes: 0

yurzui
yurzui

Reputation: 214295

Update since 4.0.0-rc.1

Version is added for root selector in the DOM

enter image description here

Since angular2 version 2.3.0-rc.0 you can get version as follows:

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

export class AppComponent { 
  constructor() {
    console.log(VERSION.full); // print 2.3.0-rc.0
  }
}

Or you can just open browser console and check body tag enter image description here

Upvotes: 49

avvensis
avvensis

Reputation: 955

ng -v shows version of cli, node, os & angular.

Upvotes: 11

basarat
basarat

Reputation: 276255

The fact that current angular 2 is beta 13 combined with a simple search : https://github.com/angular/angular/search?l=typescript&p=1&q=13&type=Code&utf8=%E2%9C%93 and a look through docs https://angular.io/docs/ts/latest/api/ means that its not exposed at runtime as a simple version number

Feel free to request it as a feature here : https://github.com/angular/angular/issues

Upvotes: 1

Related Questions