Is there a way in AngularJS to define constants with other constants?

前端 未结 6 663
刺人心
刺人心 2020-12-12 10:56

I\'m trying to define constants with other constants, but it seems that it can\'t be done, because the initial constant isn\'t ready when the required constant depending req

6条回答
  •  温柔的废话
    2020-12-12 11:27

    I do that this way:

    var constants = angular.module('constants', []);
    
    constants.factory("Independent", [function() {
       return {
          C1: 42
       }
    }]);
    
    constants.factory('Constants', ["Independent", function(I) {
       return {
          ANSWER_TO_LIFE: I.C1
       }
    }]);
    

提交回复
热议问题