在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}) }); });
如果connection.properties是驻留在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