question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unknown provider: DTOptionsBuilderProvider <- DTOptionsBuilder <- dataRefreshController

See original GitHub issue

It’s my first time using angular-datatables and DataTables. I’m following the “With a function that returns a promise”-example. However I get the error: [$injector:unpr] Unknown provider: DTOptionsBuilderProvider <- DTOptionsBuilder <- dataRefreshController

What am I doing wrong? In my code I have an app.js, controller.js and service.js file.

The app.js file contains the following:

(function () {
    'use strict';

    angular.module('myApp', ['ngRoute', 'datatables', 'datatables.bootstrap'])
        .config(configFunction);

    configFunction.$inject = ['$routeProvider', '$locationProvider'];
    function configFunction($routeProvider, $locationProvider) {
        $locationProvider.html5Mode(true);
        $routeProvider
            .when('/', {
                templateUrl: '/Home/HomePage'
            })
            .when('/Home/About', {
                templateUrl: '/Home/About'
            })
            .when('/Home/Contact', {
                templateUrl: '/Home/Contact'
            })
            .when('/DataRefresh/Schedule', {
                templateUrl: '/DataRefresh/Schedule'
            })
        ;
    }
})();

The controller.js file contains the following:

(function () {
    'use strict';

    angular.module('myApp').controller('dataRefreshController', dataRefreshController);

    dataRefreshController.$inject = ["DTOptionsBuilder", "DTColumnBuilder", "dataRefreshService"];
    function dataRefreshController(DTOptionsBuilder, DTColumnBuilder, dataRefreshService) {
        var drc = this;

        drc.dtOptions = DTOptionsBuilder.fromFnPromise(function () {
            return dataRefreshService.getDataRefreshSchedule();
        }).withPaginationType('full_numbers').withBootstrap();

        drc.dtColumns = [
            DTColumnBuilder.newColumn('column_1').withTitle('Column 1'),
            DTColumnBuilder.newColumn('column_2').withTitle('Column 2'),
            DTColumnBuilder.newColumn('column_3').withTitle('Column 3'),
        ];
    }
})();

The service.js file contains the following:

(function () {
    'use strict';

    angular.module('myApp').service('dataRefreshService', dataRefreshService);

    dataRefreshService.$inject = ["$http", "$cacheFactory"];
    function dataRefreshService($http, $cacheFactory) {
        this.getDataRefreshSchedule = function () {
            return $http({
                method: 'get',
                url: '/api/schedule'
            });
        };
    }
})();

The order the JavaScript files are added to my page is:

<script src="/Scripts/jquery-2.2.0.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/DataTables/jquery.dataTables.js"></script>
<script src="/Scripts/DataTables/dataTables.bootstrap.js"></script>
<script src="/Scripts/angular.js"></script>
<script src="/Scripts/angular-resource.js"></script>
<script src="/Scripts/angular-route.js"></script>
<script src="/Scripts/angular-datatables.js"></script>
<script src="/Scripts/angular-datatables.plugins/angular-datatables.bootstrap.js"></script>
<script src="/Scripts/ng-app/app.js"></script>
<script src="/Scripts/ng-app/controller.js"></script>
<script src="/Scripts/ng-app/service.js"></script>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
BraveThrashercommented, Mar 23, 2016

The project uses angularJS 1.5

In the meantime I also tried to setup a plnkr but I could not get it reproduced 😦 Because of this and as a test, I replaced the 7 .js files from the src back with the angular-datatables.js file from the dist folder and… lo and behold… it worked. Not sure why because as far as I can tell nothing changed.

0reactions
ppumkincommented, Mar 13, 2017

Well I removed all the separate files and just used the single angular-datatables.js I found … somewhere. Cause I was not going to install npm and node.js just to build this plugin. I think I used the compiled file used on the demo page

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Datatables: Unknown provider - Stack Overflow
So I've decided to try building my datatable with ajax and building my columns with dtOptionsBuilder and filling the table using dtOptions. However,...
Read more >
Angular Datatables: Unknown provider
So I've decided to try building my datatable with ajax and building my columns with dtOptionsBuilder and filling the table using dtOptions.
Read more >
angularjs + datatables directive throwing Error: $injector
Actually we tried without the 'datatables' module but then it gives "Error: $injector:unpr Unknown provider: DTOptionsBuilderProvider <- DTOptionsBuilder ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found