Woot4Moo Woot4Moo - 6 months ago 736
AngularJS Question

angularjs read from properties file

In angularJS how can I read a value from a properties file?

connection.properties:

url="http://localhost:8080"
user= "me"
get= "GET"
post= "POST"


app.js:

var app = angular.module('testing',[]);
app.controller('testCtrl',function($scope,$http) {
$http({
url: connection.properties.url ,
method: connection.properties.get,
params: {user: connection.properties.user})
});
});

Answer

If connection.properties is a file that lives on your web server, then you simply need to do this:

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

app.controller('test', function ($scope, $http) {
  $http.get('connection.properties').then(function (response) {
    console.log('a is ', response.data.a);
    console.log('b is ', response.data.b);
  });
});

You can see an example here:

http://plnkr.co/edit/3Ne3roFOwcfVmg2mgnUr?p=preview