Recently starting with AngularJs, I am honing my skills by developing a single page Todo Application. However, I have encountered an issue while trying to load a localStorage factory that I intend to use for this project. Currently, I am stuck on the error message:
'Undefined is not a function at routeconfig.resolve.store on app.js line 11.'
Below is the code snippet in question :
app.js
angular.module('TodoAngular', ['ngRoute'])
.config(function($routeProvider) {
'use strict';
var routeConfig = {
controller: 'TodoController' ,
templareUrl: 'app/partials/TodoList.html',
resolve: {
store: function (todoAngularStorage) {
return todoAngularStorage.then(function (module) {
module.get();
return module;
});
}
}
};
$routeProvider
.when('/todos', routeConfig)
.otherwise({
redirectTo: '/todos'
});
}
);
todoAngularStorage.js
angular.module('TodoAngular')
.factory('todoAngularStorage', function ($http,$injector) {
'use strict';
return $injector.get('localStorage');
})
.factory('localStorage', function($q) {
'use strict';
var STORAGE_ID = 'todoAngularLocalStorage';
var store = {
todos: [],
_getFromLocalStorage: function(){
return JSON.parse(localStorage.getItem(STORAGE_ID) || '[]');
},
_saveToLocalStorage: function (todos) {
localstorage.setItem(STORAGE_ID, JSON.stringify(todos));
},
delete: function (todo) {
var deferred = $q.defer();
store.todos.splice(store.todos.indexOf(todo), 1);
store._saveToLocalStorage(store.todos);
deferred.resolve(store.todos);
return deferred.promise;
},
get: function () {
var deferred = $q.defer();
angular.copy(store._getFromLocalStorage(), store.todos);
deferred.resolve(store.todos);
return deferred.promise;
},
insert: function (todo) {
var deferred = $q.defer();
store.todos.push(todo);
store._saveToLocalStorage(store.todos);
deferred.resolve(store.todos);
return deferred.promise;
}
};
return store;
});
Upon debugging, it seems that the issue lies within the 'module' passed in the function called in the above mentioned section of my app.js
file
return todoAngularStorage.then(function (module) {
I have been referencing this example (https://github.com/tastejs/todomvc/tree/master/examples/angularjs) for guidance while building my application and currently struggling to pinpoint where exactly I went wrong.