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

An easy way to do this is like this:

var myApp = angular.module("exampleApp",[]);

myApp.constant('RESOURCES', (function() {
  // Define your variable
  var resource="http://127.0.0.1:8008";
  // Use the variable in your constants
  return {
    USERS_DOMAIN: resource,
    USERS_API: resource + "https://stackoverflow.com/users",
    BASIC_INFO: resource + '/api/info'
  }
})());

And use the constants like this:

myApp.controller("ExampleCtrl", function(RESOURCES){
  $scope.domain = RESOURCES.USERS_DOMAIN;
});

Credits: link

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)