我试图将以下服务重构为匿名服务:
private void copyFile(File src, Uri destUri) {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(src));
bos = new BufferedOutputStream(getContentResolver().openOutputStream(destUri));
byte[] buf = new byte[5024];
bis.read(buf);
do {
bos.write(buf);
} while (bis.read(buf) != -1);
} catch (NullPointerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bis != null) bis.close();
if (bos != null) bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
像这样服务正在运作。当我重构以下内容时,它失败了:
angular.module('adress.services', [])
.factory('Adresses', function () {
var adresses = [
{
"ID": 1,
"person": "Bladiebla",
"name": "blabla",
}];
var service = {
all: all,
get: get
};
return service;
function all() {
return adresses;;
}
function get(adressId) {
for (var i = 0; i < adresses.length; i++) {
if (adresses[i].id === parseInt(adressId)) {
return adresses[i];
}
}
return null;
}
});
我不确定在让这个工作中缺少什么。该服务通过以下主服务文件加载:
(function(){
angular
.module('adress.services')
.factory('Adresses', Adresses);
function Adresses() {
var adresses = [
{
"ID": 1,
"person": "Bladiebla",
"name": "blabla",
}];
var service = {
all: all,
get: get
};
return service;
function all() {
return adresses;;
}
function get(adressId) {
for (var i = 0; i < adresses.length; i++) {
if (adresses[i].id === parseInt(adressId)) {
return adresses[i];
}
}
return null;
}
}
})();
我的控制器看起来像这样:
angular.module('starter.services', [
'adress.services',
'biography.services',
'maps.services',
'userplanning.services',
'pageFocus.services',
'timeline.services',
'users.services',
'questions.services'
]);
我收到以下错误:
.controller('AdressesCtrl', function ($scope, Adresses) {
$scope.adresses = Adresses.all();
})
答案 0 :(得分:0)
你缺少依赖,即:[]
angular
.module('adress.services',[])
.factory('Adresses', Adresses);
编辑: AngularJS包含以下核心类型的对象和组件:
Value
Factory
Service
Provider
Constant
可以使用AngularJS依赖注入机制将这些核心类型注入到彼此中。