11

angularJSでは、プロパティファイルから値を読み取るにはどうすればよいですか?

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})        
     });
});
4

3 に答える 3

14

が Web サーバー上に存在するファイルの場合connection.propertiesは、次のようにするだけです。

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);
  });
});

ここで例を見ることができます:

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

于 2013-09-30T17:32:13.507 に答える