I'd need to use a constant to reference an URL address in my AngularJS Controller. Based on the examples I have found so far I have coded (small snippet):
var app = angular.module("customerManagement", []).constant('SERVER_URL','http://localhost:8080/customers');
app.controller("customerManagementController", function ($scope, $http) {
$scope.customers = [];
$scope.form = {
id: -1,
name: "",
surname: ""
};
//Now load the data from server
_refreshPageData();
//HTTP POST/PUT methods for add/edit customers
$scope.update = function () {
var method = "";
var url = "";
var data = {};
if ($scope.form.id == -1) {
//Id is absent so add customers - POST operation
method = "POST";
url = SERVER_URL;
data.name = $scope.form.name;
data.surname = $scope.form.surname;
}
But it does not seem to work. In the console I can see:
Error: SERVER_URL is not defined
What's wrong with my constant definition? Thanks