Tuesday, April 4, 2017

how to use const vars in AngularJS

1. define const with .constant

 angular.module('myapp').constant("CONST", {
     "URL" : "www.google.com",
     "WELCOME_MSG": "Hello world",
     "PI" : 3.1415926
  }); 

2. Reference consts with:
angular.module('myapp').controller('myCtrl', ['$scope', '$rootScope', '$log', 'CONST', function($scope, $rootScope, $log, CONST) {
     $log.info("URL is", CONST.URL);
 }]);