AngularJS-将配置文件添加到项目中
AngularJS - Adding Configuration File to Project
config.properties
foo="fooTest"
bar="barTest"
configGrabber.java
//Not going to paste all the code
//It successfully returns the JSON containing the config.properties file
//path to this is /resources
load-config.js
(function () {
'use strict';
angular.module('configService', [])
.service('configFac', function ($http) {
var data;
$http.get('../api/resources').then(function (response) {
data = response.data;
});
});
}());
app.js
(function () {
'use strict';
angular.module('app', ['configService'])
.controller('appCtrl', function ($scope, configService, $q) {
var data;
$q.all([configService]).then(function (response) {
data = response[0];
});
$scope.configResources = data;
});
}());
index.html
...
<div>{{configResources.foo}}</div>
<div>{{configResources.bar}}</div>
...
所以我试图在这个项目中添加一个配置文件,这样用户就可以轻松地自定义它。JSON文件加载到config.js很好,但数据没有传输到控制器,你能在这个代码中找到任何错误或缺陷吗?
如果服务只是因为这个原因而存在,因此不需要任何其他功能,那么它可以看起来像这样:
.service('configFac', function ($http) {
return $http.get('../api/resources')
.then(function success(response) {
console.log('Success: '+JSON.stringify(response));
return response;
}, function error(error) {
console.log('Error: '+JSON.stringify(error));
return error;
});
};
相关文章:
- 使用方法将扫描的项目添加到总数中
- 如何将项目添加到Highcharts图例中
- 如何将多个项目添加到列表中
- 将项目添加到动态列表
- 如何将一个表单中的项目添加到 Rails 中另一个表单的下拉选项
- Yeoman/Grunt:向项目添加子目录
- 将项目添加到篮式过滤器与Splice ReactJS Javascript
- 通过Jquery将项目添加到HTML Select
- 向每个堆叠条形图项目添加链接
- 微风:将项目添加到复杂类型的数组中
- 运行并向nodejs项目添加单元测试
- React Redux将项目添加到列表中会转移到其他创建的列表中
- 谷歌表单:将项目添加到响应中
- react.js每n个项目添加一个开始标签或结束标签
- jquery appendTo将多个项目添加到一个容器中
- Javascript window.open() 多次将项目添加到购物车
- 在 ReactJs 状态上将项目添加到数组中,并超时以进行自我删除
- 如何将项目添加到选定的追加列表 jQuery
- 动态将项目添加到精彩弹出库
- 无论如何可以将项目添加到 DOM 中的现有列表中