Wiring the product controller with new RESTful methods

Now, let's enable the edit/delete buttons for the products. Our product controller will work pretty much in the same way as it did in Chapter 2, Building an Amazing Store Frontend with AngularJS. But this time, we will make use of the callbacks:

/* client/app/products/products.controller.js */

var errorHandler;

angular.module('meanshopApp')
  .controller('ProductsCtrl', function ($scope, Products) {
    $scope.products = Products.query();
  })

  .controller('ProductViewCtrl', function ($scope, $state, $stateParams, Products) {
    $scope.product = Product.get({id: $stateParams.id});
    $scope.deleteProduct = function(){
 Product.delete({id: $scope.product._id}, function success(/* value, responseHeaders */) ...

Get Web Application Development with MEAN now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.