一尘不染

从属性文件读取的angularjs

angularjs

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

阅读 294

收藏
2020-07-04

共1个答案

一尘不染

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

您可以在此处查看示例:

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

2020-07-04