저장소 파일에서 싱글 톤으로 작동해야하는 AngularJS 서비스를 작성하려고합니다.Singleton to Storage 파일 인 AngularJS 서비스
- 에서 저장된 파일을 가져 오기위한 키 getFilesForTabId
- 하여 파일을 작성하기위한
setFilesForTabId 나는 이런 식으로 뭔가 쓰기 위해 노력하고있어 :
을 두 가지 방법이 있어야합니다app.factory('fileStorage', ['LogService', function (LogService) {
var fileStorage = {
this.files = {};
this.getFilesForTabId = function (key) {
return this.files[key];
};
this.setFilesForTabId = function (key, files) {
this.files[key] = files;
return true;
}
}
return fileStorage;
}]);
하지만이 코드는 잘못되었습니다. 내가 그것을 사용하려고 할 때 오류가 있습니다. 내가 어떻게 쓸 수 있니? 도와 주셔서 감사합니다
이제 getFilesForTabId 기능에 문제가 있습니다. 정의되지 않은 파일 [key] 객체로이 함수를 실행하려고합니다. 내 실제 서비스 코드는 다음과 같습니다 내가 browswer에서 오류를 표시 아래
app.factory('fileStorage', ['LogService', function (LogService) {
var fileStorage = {
files: {},
setFilesForTabId: function(key,files){
this.files[key] = files;
return true;
},
getFilesForTabId: function (key) {
if(typeof(files[key]) === undefined) {
return [];
}
else{
return this.files[key];
}
}
}
return fileStorage;
}]);
"오류가 있습니다 ...."* 어떤 오류 *하세요 [편집] 오류가있는 질문?. – Claies