How to display the app version in Angular?

后端 未结 10 1549
暗喜
暗喜 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 05:08

    I don't think that "Angle Bracket Percent" has anything to do with angular1. That's likely an interface to another API you don't realize is being used in your previous project.

    Your easiest solution: just list the version number manually in your HTML file or store it in a global variable if you are using it in multiple places:

    
    ...
    
      

    My App's Version is: {{myAppVersionNumber}}

    Your harder solution: run a build automation step that extracts the version number from your package.json file and then rewrites your index.html file (or js/ts file) to include the value:

    • Could simply import or require the package.json file, if you're working in an environment that supports it:

      var version = require("../package.json").version;

    • This could also be done in a bash script that reads the package.json and then edits another file.

    • You could add an NPM script or modify your start script to make use of additional modules to read and write files.
    • You could add grunt or gulp to your pipeline and then make use of additional modules to read or write files.

提交回复
热议问题