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}) }); }); 
+8
javascript angularjs properties
source share
2 answers

If connection.properties is the file that lives on your web server, you just 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); }); }); 

Here you can see an example:

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

+12
source share

The easy way is

  • create js file named

    "config.js" (valid in /config/config.js path scripts)

    config.js:

    var test1 = "http://testurl.com" var test2 = "globalconstant"

  • On the html page, enable this config.js at the top (above the main controller.js): **<script.. src="./scripts/config/config.js"></st>**

  • In the controller, make the following change:

    MainController.js: $ scope.appUrl = test1; $ scope.appConstant = test2;

+2
source share

All Articles