Reputation: 25
How can i use $scope into a function
my code is and $scope.products do not work:
$http.get('catalog/view/theme/default/template/confirm/fetch_product.php').then(function(response){ $scope.products = response.data.records; });
$scope.items = [];
var counter = 0;
$scope.loadMore = function($scope) {
var last = $scope.products.length;
for (var i = 0; i < 10; i++) {
if(counter >= last) { break; }
$scope.items.push($scope.products[counter]);
counter += 1;
}
};
$scope.loadMore();
Upvotes: 1
Views: 37
Reputation: 136184
Remove $scope
function from loadMore
function. It is killing existence of controller $scope
& inside loadMore
function $scope
will be undefined.
$scope.loadMore = function($scope) { //<== remove `$scope` from function parameter
Also you can't get $scope.products
object because you are calling loadMore
method as soon as your controller get initialize. I think you should wait till initial collection of $http.get
loads $scope.products
& inside .then
you should be calling $scope.loadMore();
function.
Upvotes: 2