1

I have an issue with my angularjs. I'm trying to add ui-scroll but when I do that I have this error.

Maybe it's because the data is not loaded when the html call it.

Error: $injector:unpr

Unknown provider: datasourceProvider <- datasource

This is my service

app.factory('actionScroll', function ($http, $timeout,$q) {
    return {
        default: {
            first: 0,
            max: 5,
            delay: 100
        },
        data: [],
        init: function (donne) {
            this.first = this.default.first;
            this.max = this.default.max;
            this.delay = this.default.delay;

            for (var i = this.first; i <= this.max; i++) {
                this.data[i] = {
                    index: i,
                    content: donne[i]
                };
            }
        },

        request: function (index, count) {
            var self = this;
            var deferred = $q.defer();

            var start = index;
            var end = index + count - 1;

            $timeout(function () {
                var item, result = [];
                if (start <= end) {
                    for (var i = start; i <= end; i++) {
                        if (item = self.data[i]) {
                            result.push(item);
                        }
                    }
                }
                deferred.resolve(result);
            }, self.delay);

            return deferred.promise;
        }
    }
})

this is my app.js

$scope.list= function () {
    $http.get(requestURL).then(function (response) {
        actionScroll.init(response.data.Liste)
        $scope.datasource = {
            get: function (index, count, success) {
                console.log('requested index = ' + index + ', count = ' + count);
                actionScroll.request(index, count).then(function (result) {
                    console.log('resolved ' + result.length + ' items');
                    success(result);
                });
            }
        };
    })
}

$scope.list()

This is my html

<ul class="viewport" ui-scroll-viewport>
    <li ui-scroll="item in datasource" adapter="adapter" buffer-size="5">
        <span class="title">{{item}}</span>
    </li>
</ul>
5
  • I see you're using $q, but it's not being injected. Commented Feb 28, 2022 at 15:15
  • @JacobStamm I add $q but I still have the same issue Commented Feb 28, 2022 at 15:17
  • Is your JS getting minified? Commented Feb 28, 2022 at 15:22
  • @JacobStamm yes Commented Feb 28, 2022 at 15:27
  • Your factories, controllers, directives, etc. need to use the proper minification-safe syntax instead of the shortcut syntax. Commented Feb 28, 2022 at 15:29

1 Answer 1

1

Maybe try loading the component only when the data is available / returned from the api:

$scope.list= function () {
    $scope.isDataLoaded= false;
    $http.get(requestURL).then(function (response) {
        $scope.isDataLoaded= true
    ...
})
<ul ng-if="isDataLoaded" class="viewport" ui-scroll-viewport>
    <li ui-scroll="item in datasource" adapter="adapter" buffer-size="5">
        <span class="title">{{item}}</span>
    </li>
</ul>
Sign up to request clarification or add additional context in comments.

1 Comment

Oh nice it was that simple ^^' Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.