O'Reilly logo

Mastering AngularJS for .NET Developers by Mohammad Wadood Majid, Golrokh Mirzaei

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

CRUD operations using $resource

In order to expose a RESTful web API, we can use the $http service, as shown in the previous CRUD operation using $http section. As we can see, in order to use $http, we created the methods Create, Read, and so on. However, on the other hand, we can use $resource, which provides a higher level of abstraction built on top of $http. The ngResource module is not included in the AngularJS framework:

var app = angular.module('myApp', ['ngResource']);

First, in our controller, we create a function named customerResources:

<!-- RETREIVE DATA FROM DATABASE WITH $resource & WEB API -- > app.controller('ctrlCustomer', function ($scope, $http) { var customerResource = $resource('/api/Customer/Customer', {}, { 'get': { method: ...

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