Storing application configuration settings

前端 未结 5 663
你的背包
你的背包 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:21

    You can use the constant() provider!

    app.constant('myAppConfig', {ver: '1.2.2', bananas: 6, hammocks: 3, bananaHammocks: true});
    

    This is not a whole lot different from Terry's solution, but constants don't change so they are applied before the other providers. Also, this module can be injected into your config function.

    app.config(function(myAppConfig){
        console.log(myAppConfig.bananaHammocks);
    });
    

    have fun

提交回复
热议问题