我的 angularjs 有問題。我正在嘗試添加 ui-scroll,但是當我這樣做時,我遇到了這個錯誤。
也許是因為 html 呼叫它時沒有加載資料。
錯誤:$injector:unpr
未知提供者:datasourceProvider <- datasource
這是我的服務
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;
}
}
})
這是我的 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()
這是我的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>
uj5u.com熱心網友回復:
也許只有在資料可用/從 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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/434274.html
