ng-admin icon indicating copy to clipboard operation
ng-admin copied to clipboard

Unknown provider: totalItemsProvider <- totalItems <- ListController

Open collinforrester opened this issue 7 years ago • 2 comments

Scope

If you have a usage question, please ask on StackOverflow or Gitter (live chat)

This form is for reporting bugs in or adding enhancements to ng-admin.

Prerequisites

Description

Version: 1.0.6 Angular: 1.6.x and 1.5.x

Any entity list view throws the error Unknown provider: totalItemsProvider <- totalItems <- ListController (only code in the project is below).

var admin = nga.application('My First Admin')
    .baseApiUrl('http://jsonplaceholder.typicode.com/'); // main API endpoint
  // create a user entity
  // the API endpoint for this entity will be 'http://jsonplaceholder.typicode.com/users/:id
  var user = nga.entity('users');
  // set the fields of the user entity list view
  user.listView().fields([
      nga.field('name'),
      nga.field('username'),
      nga.field('email')
  ]);
  // add the user entity to the admin application
  admin.addEntity(user);
  // attach the admin application to the DOM and execute it
  nga.configure(admin);

Steps to Reproduce

Unfortunately I can't get the error to reproduce in plunkr because I don't know if its related to webpack or an angular version problem with this library.

I'm posting here so that I hope someone sees this and has come across this before.

Doing some digging....

I assume it comes from this controller function ListController($scope, $stateParams, $location, $anchorScroll, ReadQueries, progression, view, dataStore, totalItems).

The only place I can find a totalItems resolver is here inside of ReadQueries:

return this.getRawValues(view.entity, view.name(), view.type, page, view.perPage(), allFilterValues, view.filters(), sortField, sortDir, url).then(function (values) {
                return {
                    data: values.data,
                    totalItems: values.totalCount || values.headers('X-Total-Count') || values.data.length
                };
            });

and here inside of routing.js

totalItems: ['response', function (response) {
                        return response.totalItems;
                    }],

If I put a breakpoint on either one, it never gets hit and the error gets thrown before.

Do we have any example apps of angular 1.5.x or 1.6.x using latest webpack? Maybe I'm missing something there.

collinforrester avatar May 19 '17 20:05 collinforrester

Still narrowing it down... but I think my suspicions were right - When I link to https://cdn.jsdelivr.net/npm/[email protected]/build/ng-admin.min.js using a regular

collinforrester avatar May 20 '17 14:05 collinforrester

Hi,

You are right, the totalItems "provider" is defined in the routing. I don't know if it is related to the wepack build, but it seems that the response argument doesn't have a totalItems attribute.

Can you provide a way to reproduce the issue ? How do you import ng-admin ? What is your webpack configuration ?

To help you find the issue, you can install ng-admin locally and use it as a dependency for your project:

Install ng-admin locally and make it available for link

git clone [email protected]:marmelab/ng-admin.git
cd ng-admin
make install && make transpile
npm link

Use your local ng-admin to debug your project

npm link ng-admin

From here, your node_modules/ng-admin folder will be a symbolic link to your ng-admin fork and you'll can console.log or whatever you want. Don't forget to transpile after each change.

Kmaschta avatar May 20 '17 20:05 Kmaschta