Configuration file in AngularJS

前端 未结 3 475
心在旅途
心在旅途 2020-12-07 11:05

What is the best way to create config file (Something like web config in .net), for storing urls, and other constants that may vary during the application deploy?

3条回答
  •  隐瞒了意图╮
    2020-12-07 11:53

    IMHO, I don't like handling config files with task runners. Cause you will need to rebuild your whole application just to change a line or two every time you need a different configuration.

    Using the .config of angular is a good thing and I would do something like (borrowing from the example of the first answer)

    angular.module('app').constant('MONGOLAB_CONFIG', {
      baseUrl: '/databases/',
      dbName: 'ascrum'
    });
    

    let's name this as app.config.js

    And this will be linked in the .html right after the minified script like this

     //the application's minified script
    
    

    You can just then edit the app.config.js file without re running any tasks. So you can have different app.config.js files on different machines/environments without re building the app again and again

提交回复
热议问题