I am currently trying to use the bLazy lazy loading script in combination with angular2 and ionic2.
Using the javascript by itself only with HTML works like a charm and as expected:
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/blazy/1.6.2/blazy.min.js"></script>
</head>
<body>
<script>
// Example
var bLazy = new Blazy({
src: 'blazy-data' // Default is data-src
});
</script>
<style>
.b-lazy {
-webkit-transition: opacity 500ms ease-in-out;
-moz-transition: opacity 500ms ease-in-out;
-o-transition: opacity 500ms ease-in-out;
transition: opacity 500ms ease-in-out;
max-width: 100%;
opacity: 0;
}
.b-lazy.b-loaded {
opacity: 1;
}
.imgbg {
background-color:#b0b0b0;
max-width: 400px;
padding: 2px;
border-color: #fff;
border-style: solid;
}
</style>
<div class="imgbg"><img class="b-lazy" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw" blazy-data="http://lorempixel.com/400/400/abstract" border="1" width="400" height="400" /></div>
<div class="imgbg"><img class="b-lazy" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw" blazy-data="http://lorempixel.com/400/400/fashion" border="1" width="400" height="400" /></div>
<div class="imgbg"><img class="b-lazy" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw" blazy-data="http://lorempixel.com/400/400/city" border="1" width="400" height="400" /></div>
<div class="imgbg"><img class="b-lazy" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw" blazy-data="http://lorempixel.com/400/400/sports" border="1" width="400" height="400" /></div>
<div class="imgbg"><img class="b-lazy" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw" blazy-data="http://lorempixel.com/400/400/people" border="1" width="400" height="400" /></div>
</body>
</html>
This one shows the placeholders for images being lazy loaded, and as soon as they come into the viewport, the get loaded and shown. (Same code as jsfiddle here)
When using the same DIVs inside an ionic2 app, the lazy loading does not work. Please note that I already use the mechanism mentioned in the documentation about using bLazy with angular.
It simply does not load the images after first initialization. So I thought it might be a timing problem, but even when using a button to call the revalidate method of bLazy, it only loads the images inside the viewport, all other images are ignored.
Please check this plunkr for an example: https://plnkr.co/edit/5LoBQ389PQv4AlBTlbjw?p=preview
Does anybody know a workaround for this or how to correctly use bLazy together with ionic2?
Thanks in advance.