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

Exercising CRUD with $resource

The Exercise resource defined in WorkoutService already has the save and update (custom actions that we added) action. It's now just a matter of invoking the correct action inside the WorkoutBuilderService functions.

The first ExerciseBuilderService function we fix is save. Update the save implementation with the following code:

service.save = function () {
    if (!buildingExercise._id)
    buildingExercise._id = buildingExercise.name;
    var promise = newExercise ?
       WorkoutService.Exercises.save({},buildingExercise).$promise
      : buildingExercise.$update({ id: buildingExercise.name });
    return promise.then(function (data) {
        newExercise = false;
        return buildingExercise;
});
};

In the previous implementation based on the newExercise ...

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