angularjs从属性文件中读取

Woo*_*Moo 11 javascript properties angularjs

在angularJS中,如何从属性文件中读取值?

connection.properties:  

url="http://localhost:8080"  
user= "me"  
get= "GET"  
post= "POST"
Run Code Online (Sandbox Code Playgroud)

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})        
     });
});
Run Code Online (Sandbox Code Playgroud)

Lan*_*don 14

如果connection.properties是您的Web服务器上的文件,那么您只需要这样做:

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);
  });
});
Run Code Online (Sandbox Code Playgroud)

你可以在这里看到一个例子:

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