I am currently implementing $http for querying data with angular datatable. How could $resource be implemented instead?

function serverData(sSource, aoData, fnCallback, oSettings) {
    var request = {
        method: 'POST',
        url: '/datatable/post/'
    }

    $http(request).then((data) => {                        
            fnCallback(data.data);                        
        });
}

$scope.dtOptions = DTOptionsBuilder.newOptions()
    .withDataProp('data')
    .withOption('processing', true)
    .withOption('serverSide', true)
    .withFnServerData(serverData);
share|improve this question

Implementing this using $resource would look like:

 $resource('/datatable/post/').save({}, function(data){
   fnCallback(data.data);
 })

Additionally you would need to inject ngResource into your app like:

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

And include in your HTML like:

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-resource.js"></script>

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.