How to display the app version in Angular?

后端 未结 10 1528
暗喜
暗喜 2020-12-02 04:55

How do I display the app version in angular application? the version should be taken from package.json file

{
  \"name\": \"angular-app\",
  \"v         


        
10条回答
  •  不思量自难忘°
    2020-12-02 05:14

    Trying DyslexicDcuk's answer resulted in cannot find name require

    Then, reading 'Optional Module Loading and Other Advanced Loading Scenarios' section in https://www.typescriptlang.org/docs/handbook/modules.html helped me solve this. (Mentioned by Gary here https://stackoverflow.com/a/41767479/7047595)

    Use the below declaration to require package.json.

    declare function require(moduleName: string): any;
    
    const {version : appVersion} = require('path-to-package.json');
    

提交回复
热议问题