我想为应用程序创建一个原型,我不想调用休息服务来检索数据。为此,我想在服务(缓存)中创建我的对象,并使用这些服务来显示对象 crud。
我会在服务中使用 CacheFactory,并且对于每个 crud 操作,直接操作缓存中的对象数组。
现在我有以下代码:
缓存服务:
services.factory('TeacherCache', ['$cacheFactory', function ($cacheFactory) {
var cache = $cacheFactory('TeacherCache');
cache.put('teachers', [
{
id: 1,
clientId: 100,
username: 'teacher465462@gmail.com',
password: 'mdp',
lastName: 'THETEACHER2',
firstName: 'DE',
secondFirstName: '',
address: '9, ADRESS',
city: 'Paris',
country: 'USA',
zipCode: '7ffd5445020',
email: 'my.email@gmail.com',
homePhone: '006546546546',
cellPhone: '54415151661',
birthDate: '31/12/1958',
enabled: true,
roles: [
{id: 1, name: 'Teacher'}
],
//---------------------
substitute: false,
schoolClasses: [],
subjects: [],
options: [],
employedDate: '28/08/2013'
}
]);
return cache;
}]);
我的对象服务:
services.factory('TeacherService', 'TeacherCache', function (TeacherCache) {
return {
errorMessage: '',
create: [...],
get: function (id) {
[...]
},
//Get a list of db objects with query
query: function () {
return TeacherCache.get('teachers');
},
delete: [...]
};
})
;
但是当我在我的控制器中注入 TeacherService 并调用查询时:
var teachers = TeacherService.query();
我有以下错误:
Error: Argument 'fn' is not a function, got string
我该如何解决这个问题?谢谢你 !