Note that there are some explanatory texts on larger screens.

plurals
  1. POusing cacheFactory in service for CRUD
    primarykey
    data
    text
    <p>I want to create a prototype for an application and I don't want to call rest services to retrieve data. For this, I want to create my objects in services (cache) and to use these services to display objects crud.</p> <p>I would use CacheFactory in services, and for each crud operation, directly manipulate the array of objects in the cache.</p> <p>Now I have the following code: </p> <p>Cache service:</p> <pre><code>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; }]); </code></pre> <p>And my object service : </p> <pre><code>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: [...] }; }) ; </code></pre> <p>But when i inject TeacherService in my controller and call query :</p> <pre><code>var teachers = TeacherService.query(); </code></pre> <p>i have the following error : </p> <pre><code>Error: Argument 'fn' is not a function, got string </code></pre> <p>How can i resolve this ? thank you !</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload