1

How to use Global constants in app configuration constants.

In Constant.js

var ConstantAPI = {
  baseUrl: "http://localhost:4200",
}

In appConfiguration.js

(function () {
    'use strict';
    myModule.constant('appConfiguration', {
        getEmployee : ConstantAPI.baseUrl + '/getEmployee',
})();

Error: ConstantAPI is not defined

2 Answers 2

1

Why not define it in the constant itself. It should be something like this,

var myModule = angular.module('myApp', []);

app.constant('ConstantAPI ', {
    baseUrl: "http://localhost:4200",
});

app.provider('appConfiguration', ['ConstantAPI', function(ConstantAPI) {
   getEmployee : ConstantAPI.baseUrl + '/getEmployee',
}]);
Sign up to request clarification or add additional context in comments.

2 Comments

The ConstantAPI should be in In Constant.js file only. because i'm using in different places. can you get me solution please
in that case you need to define as a json and use http.get to get the values
0

You have to define constants in a separate file as follows.

var MyApp= angular.module("myapp");

MyApp.constant("ConstantAPI",
{
  baseUrl: "http://localhost:4200",      
});

Check this Plunker

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.