Kar Kar - 1 year ago 97
reST (reStructuredText) Question

Managing REST endpoints in Angular JS?

Is there a best practice to store and manage all REST endpoints for an application at one location within Angular JS?

Answer Source

You can store them as constants outside application, according to this great document.

You can store such config as


(function (window) {
    window.__env = window.__env || {};

    // Login page address
    window.__env.loginUrl = 'http://website/login';


then assign it as a constant in your main module


angular.module('yourmodule', [])
    .constant('__env', __env)

and then you can inject in in your service

loginData.$inject = ['$http', '__env'];

Such configuration works best for me, is easy to manage and change depending on environment, without rebuilding application. Just assigning constant doesn't have such advantage.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download