Javascript AngularJS-将配置文件添加到项目
config.propertiesJavascript AngularJS-将配置文件添加到项目,javascript,java,angularjs,Javascript,Java,Angularjs,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';
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>
...
。。。
{{configResources.foo}
{{configResources.bar}
...
因此,我试图在这个项目中添加一个配置文件,以便用户可以轻松地自定义它。JSON文件可以加载到load-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;
});
};
如果该服务仅仅因为这个原因而存在,因此不需要任何其他功能,那么它可以如下所示:
.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;
});
};
从外观上看,您没有正确调用该服务。您需要返回i代码如何查找它?从外观上看,您没有正确调用服务。您需要返回i代码将如何查找它?现在尝试此操作,只需修复一些jslint错误现在尝试此操作,只需修复一些jslint错误