我目前在一个项目中使用ngCordova,我需要在本地存储从web-service获取的图像
$http.get('webservice/image/' + item.imageId).then(function(response) {
$cordovaFile.writeFile(
cordova.dataDirectory,
item.imageId,
response.data,
true).then(function() {
item.imagePath = cordova.dataDirectory + item.imageId;
item.update();
});
});
它将图像存储在:(我可以在Xcode中看到它们,所以它们被保存)
file:///var/mobile/Application/<appID>/Library/NoCloud/<imageId>.png
然后我尝试在视图中显示它们:
<img ng-src="{{item.imagePath}}"/>
它没有显示任何图像,我尝试了其他imagePath组合:
item.imagePath = ./Library/NoCloud/<imageId>.png
item.imagePath = Library/NoCloud/<imageId>.png
item.imagePath = ./<imageId>.png
item.imagePath = <imageId>.png
item.imagePath = ../../Library/NoCloud/<imageId>.png
我让它这样工作:
$cordovaFileTransfer.download(
encodeURI('webservice/image/' + item.imageId),
cordova.file.dataDirectory + item.ImageId, {},
true).then(function(response) {
item.Image = response.toInternalURL();
item.update();
}));