Storing application configuration settings

前端 未结 5 670
你的背包
你的背包 2021-01-31 07:39

What is the best place to store application configuration settings in AngularJS? This could be things like application constants, lookups etc. which could be used both from cont

5条回答
  •  不知归路
    2021-01-31 08:27

    You can also use provider instead of service and easy use everywhere.

    angular.module('App', []).provider('config',
    function() {
        var conf = {
            ver: '1.2.2',
            bananas: 6,
            hammocks: 3,
            bananaHammocks: true,
            baseUrl:'data/'
        };
    
        conf.$get = function () {
            delete conf.$get;
            return conf;
        };
    
        return conf;
    });
    

    Then use in config as configProvider:

    angular.module('App').config( function(configProvider) {} );
    

    In run, controllers, services, ect as config:

    angular.module('App').run( function(config) {} );
    

    Here is an example link and of code

提交回复
热议问题