Until now, we have used $http
for exercise/workout data management. To elaborate on the $resource
behavior, let's change the exercise data load and save this to use the $resource
service.
Open the services.js
file and add the following lines to the WorkoutService
implementation above the service.getExercises
function:
service.Exercises = $resource(collectionsUrl + "/exercises/:id", { apiKey: apiKey}, { update: { method: 'PUT' } });
The statement creates a Resource
class configured with a specific URL and API key. The key is passed in to the default parameter collection.
Go ahead and delete all exercise-related functions from WorkoutService
. These include the service.getExercises
, service.getExercise
, service.updateExercise
, service.addExercise
, and service.deleteExercise
functions. Everything related to the exercise will be done using resources now.
The $resource
function is part of the ngResource
module; therefore, we need to include the module script...