首页 > 解决方案 > Get AngularJS constacts

问题描述

I want to get the constant "ClientID" value from

   <script>    
    angular.module("myModule", []).constant("appSetting",

    {
        appEnvironment: 'INTRANET',

        ClientID: '0663555953',

        Scope: 'Level1',
    }    
   );
   </script>

located in startPage.aspx

to another js file. i've tried this

<script>
var ClientID = angular.module("myModule", []).constant("appSetting").(ClientID);
function myFucntion()
{    
   console.log(ClientID);
}

<script>

标签: angularjs

解决方案


您可以将常量注入控制器:

    angular.module('myModule').controller('someController',['$scope','appSetting', 
         function($scope, appSetting){
             console.log(appSetting.ClientID);
         }
    ]);

推荐阅读