O'Reilly logo

AngularJS by Example by Chandermani

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using $resource to access exercise data

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required