How to add a counter for each image upload in Ionic

I am trying to load a list of images using the counter shown when loading each image.

This is what I have, but don’t see how to add a counter when each image is loaded, instead of seeing a blank screen when loading

<div ng-repeat="i in data| filter: { tags: tag } " class='wrapper' id="homeImg">
    <!-- wrapper div -->

    <!-- image -->
    <a href="#/information"> <img class="ng-cloak" style="float:left; display:inline-block; overflow:hidden; border: 1px;" class="fill_image" src='{{ i.picture }}' style width="100%" style height="100%" ng-click="disableClick('{{ i.firebase_url }}')" /> </a>
    <!-- description div -->
    <div class='description'>
        <!-- description content -->
        <p class='description' style="float: left">
            {{i.title }}
        </p>
        <p class='description' style="float: right">
            {{i.location}}
        </p>

        <!-- end description content -->
    </div>
    <!-- end description div -->
</div>
+4
source share
1 answer

You can easily do this using the operator ||inside the tag ng-src:

Controller:

$scope.loading = "<some-pic.gif>";

View:

<!-- image -->
<a href="#/information">
    <img ng-src='{{ (i.picture) || (loading) }}'/>
</a>
  • Change the tag srcto a ng-srcmore angular friendly
  • Define the uploaded image / gif (previous upload) and save it in a variable $scope
  • ||, undefined, (gif)

Fiddle: http://jsfiddle.net/xf3ezakc/


, $ionicLoading , , , .

$scope.show = function() {
    $ionicLoading.show({
        template: 'Loading...'
    }).then(function(){
        console.log("The loading indicator is now displayed");
    });
};
$scope.hide = function(){
    $ionicLoading.hide().then(function(){
        console.log("The loading indicator is now hidden");
    });
};

// Assuming you have `$scope.data`, which it seems so
$scope.data = {};
$scope.show();
someDataCall().then(function(data) {
    // success
    $scope.hide();
}).catch(error) { 
    // error
    $scope.hide();
});

, firebase , $firebaseArray $firebaseObject, $ionicLoading $loaded, , ( API AngularFire):

$scope.data.$loaded().then(function(data) {
    // success
    $scope.hide();
}).catch(function(error) {
    // error
    $scope.hide()
});

2 , $ionicLoading

:

ng-src

$ionicLoading

AngularFire

ion-spinner ( )

+2

All Articles