Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown provider: totalItemsProvider <- totalItems <- ListController #1343

Open
collinforrester opened this issue May 19, 2017 · 2 comments
Open
Labels

Comments

@collinforrester
Copy link

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
Copy link
Author

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 <script> tag in index.html, the same code works.

@Kmaschta Kmaschta added the bug label May 20, 2017
@Kmaschta
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants