Storing application configuration settings

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

    Not sure if there is a "best way" but I personally use a service, here is an abbreviated example:

    angular.module('myApp').factory('AppSettings', function() {
      return {
        language: 'en'
      }
    });
    
    angular.module('myApp').controller('myController', ['AppSettings', 
      function(AppSettings) {
        $scope.language = AppSettings.language;
      }
    ]);
    

提交回复
热议问题