Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I want to load datatables content via $resources API call. I'm able to call the url by using

vm.dtOptions = DTOptionsBuilder.fromSource('contacts')

But using a resource that is able to access to my API endpoint would be great.

That's why I wanted to use DTOptionsBuilder.fromFnPromise, but I'm not able to call contactController.$scope.query() inside fromFnPromise

Here is my controller.js

angular.module('mainApp.controllers',[]).controller('contactController', function($scope, $location , Contact){

    $scope.contact=new Contact();
    $scope.store = function() {
        if ($scope.contact.id) {
            $scope.contact.$update();
        } else {
            $scope.contact.$save();
        }
    };

    $scope.get=function(id){
        $scope.contact.$get({id:id});
    }

    $scope.query=function(){
        $scope.contact.$query();
    }

    /* Eğer ID varsa gösterelim */
    if ($location.hash()) {
        $scope.get($location.hash());
    }
}).controller('contactListController',function($scope,Contact,DTOptionsBuilder,DTColumnBuilder){
    var vm=this;
    vm.dtOptions = DTOptionsBuilder.fromFnPromise(function(){

        //Here I want to load some thing like
        //contactController.contact.query();

    }).withPaginationType('full_numbers');
    vm.dtColumns = [
        DTColumnBuilder.newColumn('id').withTitle('ID'),
        DTColumnBuilder.newColumn('firstName').withTitle('First name'),
        DTColumnBuilder.newColumn('lastName').withTitle('Last name').notVisible()
    ];
});

service.js

angular.module('mainApp.services', []).factory('Contact', function($resource) {
    return $resource('http://localhost/invocy/api/public/contact/:id', { id: '@id' }, {
        update: {
            method: 'PUT'
        }
    });
});

list.html

<div class="row" ng-controller="contactListController as cnt">
    <div class="col s12 m12 l12">
        <div class="card-panel">
            <h4 class="header2">Contacts</h4>

            <table datatable="" dt-options="cnt.dtOptions" dt-columns="cnt.dtColumns">

            </table>

        </div>
    </div>
</div>
share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.