2016-09-07 59 views
1

在Angular 1.x中,您可以使用 angular.version來確定運行系統中的當前版本。確定當前的Angular 2.x版本

角度2.x中是否有類似的東西?我搜索了ngng.core,ng.commonng.compiler沒有任何運氣的物體。

+0

也許看看'@ angular/upgrade'模塊。像這樣的東西可能在那裏。 – martin

+0

Thx @Martin,但不幸的是它沒有。 – MEMark

回答

2

從Angular 2.3.0-rc0及更高版本中包含的this commit開始,您可以使用來自@angular/coreVERSION常量。

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

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

Live example

如果你只需要獲得開發者工具的版本,你可以試試

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

或檢查app-root元素。