1

In Angular 1.x you can determine the current version in runtime using angular.version.

Is there anything similar in angular 2.x? I have searched the ng, ng.core, ng.common and ng.compiler objects without any luck.

2
  • Maybe have a look inside @angular/upgrade module. Something like this could be there.
    – martin
    Sep 7, 2016 at 7:48
  • Thx @Martin, but unfontunately it didn't.
    – MEMark
    Sep 9, 2016 at 13:43

1 Answer 1

2

As of this commit included in Angular 2.3.0-rc0 and up, you can use the VERSION const from @angular/core.

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

@Component({
  selector: 'angular-version',
  template: '<p>Version: {{version}}</p>'
})
export class VersionComponent {
  version: string = VERSION.full;
}

Live example

If you just need to get the version in the dev tools, try something like

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

or inspect the app-root element.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.