angularjs从属性文件读取 [英] angularjs read from properties file
本文介绍了angularjs从属性文件读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在angularJS我怎么可以读取从属性值文件?
connection.properties:URL =HTTP://本地主机:8080
用户=我
得到=GET
后=POST
app.js:
VAR应用= angular.module('测试',[]);
app.controller('testCtrl',函数($范围,$ HTTP){
$ HTTP({
网址:connection.properties.url,
方法:connection.properties.get,
PARAMS:{用户:connection.properties.user})
});
});
解决方案
如果 connection.properties
是生活在Web服务器上,那么你只需要做一个文件这样的:
VAR应用= angular.module('应用',[]);app.controller(测试,函数($范围,$ HTTP){
$ http.get('connection.properties'),然后(功能(响应){
的console.log('一个是',response.data.a);
的console.log('b为',response.data.b);
});
});
您可以在这里看到一个例子:
<一个href=\"http://plnkr.co/edit/3Ne3roFOwcfVmg2mgnUr?p=$p$pview\">http://plnkr.co/edit/3Ne3roFOwcfVmg2mgnUr?p=$p$pview
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})
});
});
解决方案
If connection.properties
is a file that lives on your web server, then you simply 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);
});
});
You can see an example here:
http://plnkr.co/edit/3Ne3roFOwcfVmg2mgnUr?p=preview
这篇关于angularjs从属性文件读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文