【问题标题】:How to check Angular2 version with typescript如何使用打字稿检查 Angular2 版本
【发布时间】:2016-04-06 16:22:22
【问题描述】:

我用 angular2@2.0.0-alpha.11 编写了一个简单的应用程序,效果很好。现在我正在使用 npm 上可用的 alpha 和 beta 的最新版本对其进行测试,我一直想知道我是否真的改变了,或者我正在缓存一些东西。

我想在我的根组件上做类似下面的事情

export class ChromeComponent {

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

angular.version 在控制台返回undefined

【问题讨论】:

标签: typescript angular


【解决方案1】:

自 4.0.0-rc.1 起更新

为 DOM 中的根选择器添加版本

由于angular2版本2.3.0-rc.0可以得到如下版本:

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

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

或者你可以打开浏览器控制台并检查body标签

【讨论】:

  • @gstackoverflow new angular2 是什么意思?
  • core.umd.js:2834 例外:localhost:3000/app/app.component.html:6:4 中的错误由以下原因引起:无法读取 undefinedErrorHandler.handleError @ core.umd.js:2834(匿名函数)@跨度>
  • 从'@angular/core'导入{版本};不导入任何东西
  • 回答你的问题我需要得到我的问题的答案。目标 - 了解我的版本。我不知道。
  • 我在 DOM 中的正文没有版本信息,并且 consol logging VERSION 给出了错误
【解决方案2】:

ng -v 显示 cli、node、os 和 angular 的版本。

【讨论】:

    【解决方案3】:

    当前的 angular 2 是 beta 13 结合简单搜索的事实:https://github.com/angular/angular/search?l=typescript&p=1&q=13&type=Code&utf8=%E2%9C%93 并通过文档查看 https://angular.io/docs/ts/latest/api/ 意味着它在运行时不会作为简单的版本号公开

    请随时在此处将其作为功能请求:https://github.com/angular/angular/issues

    【讨论】:

      【解决方案4】:

      新的答案,因为在稳定的角度版本中不再接受这种情况,检查角度版本的最简单方法是在项目根目录使用 npm list 命令:

      npm list  @angular/core
      

      以防万一您也可以检查以下内容,版本应该匹配:

      npm list @angular/common
      
      npm list @angular/compiler
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-07-20
        • 1970-01-01
        • 2019-03-03
        • 2018-05-18
        • 2018-05-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多