【发布时间】:2017-09-17 11:08:13
【问题描述】:
如何以编程方式获取 angular2 的版本并在页面上呈现?
我尝试从“@angular/core”导入 { Component,Version };并尝试获取版本但没有成功。
【问题讨论】:
标签: html typescript angular2-forms
如何以编程方式获取 angular2 的版本并在页面上呈现?
我尝试从“@angular/core”导入 { Component,Version };并尝试获取版本但没有成功。
【问题讨论】:
标签: html typescript angular2-forms
console.log(Version.major);
console.log(Version.minor);
这应该给出您正在使用的主要和次要版本
【讨论】:
不要导入“版本”。导入 VERSION(大写)。示例:
版本-example.component.ts:
import { Component, VERSION } from "@angular/core";
@Component( {
templateUrl : "./version-example.component.html"
} )
export class VersionExample {
//Example 1:
theMajorVersion = VERSION.major;
//Example 2:
theMajorAndMinorVersion = `${VERSION.major}.${VERSION.minor}`; //Use backticks
//Example 3:
theFullVersion = VERSION.full;
}
版本-example.component.html:
Major version: {{theMajorVersion}}
<hr/>
Major.Minor version: {{theMajorAndMinorVersion}}
<hr/>
Full version: {{theFullVersion}}
输出示例:
主要版本:5
主要.次要版本:5.2
完整版:5.2.0
【讨论】: