GithubHelp home page GithubHelp logo

tjoskar / ng-lazyload-image Goto Github PK

View Code? Open in Web Editor NEW
764.0 27.0 143.0 4.42 MB

πŸ–Ό A small library for lazy loading images for Angular apps with zero dependencies

Home Page: https://naughty-bose-ec1cfc.netlify.com

License: MIT License

TypeScript 99.45% HTML 0.42% CSS 0.14%
angular lazy-loading

ng-lazyload-image's Introduction

ng-lazyload-image

Status npm npm version License Build Status

A super small libary for lazy loading images for Angular apps with zero dependencies

πŸ“ Table of Contents

🀯 Demo

Visit this site: https://naughty-bose-ec1cfc.netlify.com

βœ… Prerequisites

The browser you are targeting need to have support of WeakMap and String.prototype.includes. If you need to support an older browser (like IE) you will need to include polyfill for WeakMap and String.prototype.includes (see https://github.com/zloirock/core-js for example).

Make also sure to inclue a pollyfill for IntersectionObserver if you need to target IE and want to use IntersectionObserver: https://github.com/w3c/IntersectionObserver/tree/master/polyfill

⬇️ Install

To install the package, just run:

$ npm install ng-lazyload-image

or the following if you are using yarn

$ yarn add ng-lazyload-image

πŸ›  Setup

Include the library in your module (see app.module.ts):

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LazyLoadImageModule } from 'ng-lazyload-image'; // <-- import it
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, LazyLoadImageModule], // <-- and include it
  bootstrap: [AppComponent],
})
export class MyAppModule {}

IntersectionObserver

ng-lazyload-image is using a intersection observer by default so you don't need to do anything if you want to continue using the intersection observer as event emitter.

Scroll listener

You can easily swtich from IntersectionObserver to scroll listener by using the scrollHooks:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LazyLoadImageModule, LAZYLOAD_IMAGE_HOOKS, ScrollHooks } from 'ng-lazyload-image'; // <-- include ScrollHooks
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, LazyLoadImageModule],
  providers: [{ provide: LAZYLOAD_IMAGE_HOOKS, useClass: ScrollHooks }], // <-- Declare that you want to use ScrollHooks
  bootstrap: [AppComponent],
})
export class MyAppModule {}

See hooks below for more information.

πŸ–Ό Usages

A simple usecase is to use a img-tag and give it the image to lazyload to [lazyLoad] and an optional default image to [defaultImage]. The default image will be shown while the "real" image is getting loaded.

Example:

import { Component } from '@angular/core';

@Component({
  selector: 'image',
  template: ` <img [defaultImage]="defaultImage" [lazyLoad]="image" /> `,
})
class ImageComponent {
  defaultImage = 'https://www.placecage.com/1000/1000';
  image = 'https://images.unsplash.com/photo-1443890923422-7819ed4101c0?fm=jpg';
}

Background images

It also supports background images:

@Component({
  selector: 'image',
  template: ` <div [defaultImage]="defaultImage" [lazyLoad]="image"></div> `,
})
class ImageComponent {
  defaultImage = 'https://www.placecage.com/1000/1000';
  image = 'https://images.unsplash.com/photo-1443890923422-7819ed4101c0?fm=jpg';
}

Responsive images

If using responsive images in a plain <img> tag, you'll need to set the useSrcset attribute to true:

@Component({
  selector: 'image',
  template: ` <img [defaultImage]="defaultImage" [lazyLoad]="images" [useSrcset]="true" /> `,
})
class ImageComponent {
  defaultImage = 'https://www.placecage.com/1000/1000';
  images = `https://images.unsplash.com/photo-1434725039720-aaad6dd32dfe?fm=jpg 700w,
            https://images.unsplash.com/photo-1437818628339-19ded67ade8e?fm=jpg 1100w`;
}

If using responsive images in a <picture> tag, set the default <img> tag as usual with lazyLoad etc. attributes.
You can use attr.lazyLoad, attr.defaultImage and attr.errorImage attributes for <source> elements.
There's no need to set useSrcset for <source> elements, as srcset is used by default.
A simple example for a <picture> tag:

@Component({
  selector: 'image',
  template: `
    <picture>
      <source media="(min-width: {{ screen_lg }})" [attr.defaultImage]="defaultImage" [attr.lazyLoad]="image2" />
      <source media="(min-width: {{ screen_md }})" [attr.defaultImage]="defaultImage" [attr.lazyLoad]="image3" />
      <img [defaultImage]="defaultImage" [lazyLoad]="image1" />
    </picture>
  `,
})
class ImageComponent {
  screen_lg = '1200px';
  screen_md = '992px';
  defaultImage = 'https://www.placecage.com/1000/1000';
  image1 = 'https://images.unsplash.com/photo-1422004707501-e8dad229e17a?fm=jpg';
  image2 = 'https://images.unsplash.com/photo-1439931444800-9bcc83f804a6?fm=jpg';
  image3 = 'https://images.unsplash.com/photo-1417128281290-30a42da46277?fm=jpg';
}

Loading image path async

You can load image async or change the url on the fly, eg.

<img [lazyLoad]="image$ | async" />

Custom observable

Sometimes you want to get more controll over when the we should check if the image is in viewport. customObservable let's you create your own observable.

This will change the functionality of when we chek if the image is in the viewport. It does not change the functionality of how to detect if an image is in the viewport or not. Meaning: if you are using IntersectionObserver (default), it is important that the obserer that you pass to customObservable will emit objects that looks like: { isIntersecting: boolean }. You can change this behavior by implementing your own isVisible (see hooks below for more information).

If you are using the ScrollHooks-preset, you can just pass customObservable and the reset will be handle automatically.

import { merge, fromEvent } from 'rxjs'

...

constructor() {
  this.scroll$ = merge(
    fromEvent(window, 'scroll'),
    fromEvent(someDivRef, 'scroll')
  );
}
<img [customObservable]="scroll$" ... />

Ionic

If you are using Ionic and don't want to use IntersectionObserver, you may need to include your own scroll observable or change the scroll target. For instans if you want to have multiple scroll targets:

@Component({
  selector: 'page-image',
  template: `
    <ion-content #container padding>
      <img [defaultImage]="https://www.placecage.com/1000/1000" [lazyLoad]="lazyLoadImage" [customObservable]="container.ionScroll" />
    </ion-content>
  `,
})
export class AboutPage {
  lazyLoadImage = 'https://hd.unsplash.com/photo-1431400445088-1750c997c6b5';
}

In case of using ion-slides in Ionic 2+, you can include your own scroll observable as below.

@Component({
  selector: 'page-image',
  template: `
    <ion-content #container padding>
      <img [defaultImage]="https:  //www.placecage.com/1000/1000" [lazyLoad]="lazyLoadImage" [customObservable]="container.ionSlideWillChange" />
    </ion-content>
  `,
})
export class AboutPage {
  lazyLoadImage = 'https://hd.unsplash.com/photo-1431400445088-1750c997c6b5';
}

πŸ› Debug

In order to get a better understanding of what is happening you can pass [debug]="true" which will output some debug information in the web console.

See onStateChange for more information about the diffrent output messages.

πŸ’… CSS

The css class name ng-lazyloading will automatically be added before the image is loaded and will be removed when the image has been loaded or if the image couldn't be loaded.

The css class name ng-lazyloaded will be added when the image is loaded (regardless of if the image could be loaded or not).

The css class name ng-failed-lazyloaded will be added when the image couldn't be loaded.

πŸ”„ API

lazyLoad

Type: string

Example: https://images.unsplash.com/photo-1443890923422-7819ed4101c0?fm=jpg

The image to be lazy loaded. This image will replace the default image (defaultImage).

<img [defaultImage]="'https://www.placecage.com/1000/1000'" [lazyLoad]="'https://hd.unsplash.com/photo-1431400445088-1750c997c6b5'" />
defaultImage (optional)

Type: string

Example: https://www.placecage.com/1000/1000

Path to default image. This image will be loaded right away.

You can also use src attribute for img tag to define default image:
<img src="https://www.placecage.com/1000/1000" [lazyLoad]="lazyLoadImage" />

or background-image property for non-image tags:
<div style="background-image: url('https://www.placecage.com/1000/1000');" [lazyLoad]="lazyLoadImage"></div>

errorImage (optional)

Type: string

Example: https://i.imgur.com/XkU4Ajf.png

An image to be loaded if failing to load lazyLoad. Will load the default image (defaultImage) if absent.

<img [defaultImage]="someDefaultImage" [lazyLoad]="imageToLazyLoad" [errorImage]="imageToShowOnError" />
offset (optional)

Type: number

Example: 100

Default: 0

Number of px a image should be loaded before it is in view port

<img [defaultImage]="someDefaultImage" [lazyLoad]="imageToLazyLoad" [offset]="100" />
scrollTarget (optional)

Type: Element

Example: document.getElementById('my-scroll-container')

Default: window

You will need to set this property if you are using a scroll container and do not propagate the scroll event to window.

customObservable (optional)

Type: Observable

Example: Observable.fromEvent(myScrollContainer, 'scroll')

You can pass your own observable if you need more control over the flow. Can be useful if integrating with other frameworks like ionic. See Custom Observable for more information.

useSrcset (optional)

Type: boolean

Example: true

You can set this to true if you need to lazy load images with srcset attribute, instead of src.
<source> tags are set to use srcset by default, so you don't need to set this option additionaly.

decode (optional)

Type: boolean

Example: true

You can set this to true, the image will be decoded before inserted into the DOM. This can be useful for large images.

debug (optional)

type: boolean

Exaple: true

See debug for more information.

Events

onStateChange (optional)

Type: Function: (event: StateChange) => void

Example: <img [lazyLoad]="lazyLoadImage" (onStateChange)="myCallbackFunction($event)">

You can pass a callback function, which will be called when the image is getting into different state.

myCallbackFunction(event: StateChange) {
  switch (event.reason) {
    case 'setup':
      // The lib has been instantiated but we have not done anything yet.
      break;
    case 'observer-emit':
      // The image observer (intersection/scroll/custom observer) has emit a value so we
      // should check if the image is in the viewport.
      // `event.data` is the event in this case.
      break;
    case 'start-loading':
      // The image is in the viewport so the image will start loading
      break;
    case 'mount-image':
      // The image has been loaded successfully so lets put it into the DOM
      break;
    case 'loading-succeeded':
      // The image has successfully been loaded and placed into the DOM
      break;
    case 'loading-failed':
      // The image could not be loaded for some reason.
      // `event.data` is the error in this case
      break;
    case 'finally':
      // The last event before cleaning up
      break;
  }
}

🎣 Hooks

It is possible to hook into the loading process by create your own functions.

For example, let's say you want to fetch an image with some custom headers. If so, you can create a custom hook to fetch the image:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LazyLoadImageModule, IntersectionObserverHooks, Attributes, LAZYLOAD_IMAGE_HOOKS } from 'ng-lazyload-image';
import { AppComponent } from './app.component';

export class LazyLoadImageHooks extends IntersectionObserverHooks {
  loadImage({ imagePath }: Attributes): Promise<string> {
    return fetch(imagePath, {
      headers: {
        Authorization: 'Bearer ...',
      },
    })
      .then((res) => res.blob())
      .then((blob) => URL.createObjectURL(blob));
  }
}

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, LazyLoadImageModule],
  providers: [{ provide: LAZYLOAD_IMAGE_HOOKS, useClass: LazyLoadImageHooks }],
  bootstrap: [AppComponent],
})
export class MyAppModule {}

You can even use other services by inject them. Lets say you want to use Angulars https class instead of window.fetch:

import { NgModule, Injectable } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { LazyLoadImageModule, IntersectionObserverHooks, Attributes, LAZYLOAD_IMAGE_HOOKS } from 'ng-lazyload-image';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { AppComponent } from './app.component';

@Injectable()
export class LazyLoadImageHooks extends IntersectionObserverHooks {
  private http: HttpClient;

  constructor(http: HttpClient) {
    super();
    this.http = http;
  }

  loadImage({ imagePath }: Attributes): Observable<string> {
    // Load the image through `HttpClient` and cancel the request if the user change page or the image gets removed
    return this.http.get(imagePath, { responseType: 'blob' }).pipe(map(blob => URL.createObjectURL(blob)));
  }
}

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, HttpClientModule, LazyLoadImageModule],
  providers: [{ provide: LAZYLOAD_IMAGE_HOOKS, useClass: LazyLoadImageHooks }],
  bootstrap: [AppComponent],
})
export class MyAppModule {}

The following hooks are supported:

getObservable

Should return an observable that emits a new value every time ng-lazyload-image should check if the image is in viewport. It is important that the emited event is of the same type isVisible expects.

Eg.

import { Attributes, IntersectionObserverHooks } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  getObservable(attributes: Attributes) {
    // Will emit `{ isIntersecting: true }` every second.
    // You will have to overwride `isVisible` if you want to pass another event
    return interval(1000).pipe(mapTo({ isIntersecting: true })));
  }
}

A more usefull example could be to add a debounce time so we only start loading the image if it has been in the view port for some time:

import { Attributes, IntersectionObserverHooks } from 'ng-lazyload-image';
import { debounceTime } from 'rxjs/operators';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  getObservable(attributes: Attributes) {
    // Only load the image if it has been in the viewport for one second
    return super.getObservable(attributes).pipe(debounceTime(1000))
  }
}

See intersection-listener.ts for example.

See isVisible if you want to use your own event.

isVisible

Function to check if the element is vissible.

Eg.

import { Attributes, ScrollHooks } from 'ng-lazyload-image';

class LazyLoadImageHooks extends ScrollHooks {
  isVisible(event: Event | string, { element, scrollContainer, offset }: Attributes) {
    // `event` is form `getObservable`
    return isElementInViewport(element, scrollContainer, offset);
  }
}

If you want to create your own event, you can create both getObservable and isVisible by extend SharedHooks:

import { Attributes, SharedHooks } from 'ng-lazyload-image';

class LazyLoadImageHooks extends SharedHooks<number> {

  getObservable(attributes: Attributes) {
    return interval(1000);
  }

  isVisible(event: number, attributes: Attributes) {
    // `event` is 0,1,2,3,4,5,...
    return isElementInViewport(element, scrollContainer, offset);
  }
}

loadImage

Function to load the image. It must return a path to the image (it can however be async, like the example below and/or return a observable).

import { IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  loadImage({ imagePath }: Attributes): Promise<string> {
    return await fetch(imagePath)
      .then((res) => res.blob())
      .then((blob) => URL.createObjectURL(blob));
  }
}

If you don't want to load the image but instead let the browser load it for you, then you can just return the imagePath (We will however not know if the image can't be loaded and the error image will not be used):

class LazyLoadImageHooks extends IntersectionObserverHooks {
  loadImage({ imagePath }: Attributes) {
    return [imagePath];
  }
}

setLoadedImage

A function to set the image url to the DOM.

Eg.

import { IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  setLoadedImage({ element, imagePath }: Attributes) {
    // `imagePath` comes from `loadImage`
    element.src = imagePath;
  }
}

setErrorImage

This function will be called if the lazy image cant be loaded.

Eg.

import { IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  setErrorImage({ element, errorImagePath }: Attributes) {
    element.src = errorImagePath;
  }
}

setup

This function will be called on setup. Can be useful for (re)setting css-classes and setting the default image.

This function will be called every time an attrebute is changing.

Eg.

import { IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  setup(attributes: Attributes) {
    // Overwride the path to the default image for all lazyloaded images
    attributes.defaultImagePath = 'some/path.jpg';
    // You can always call the base `setup` if you want to keep the default behavior
    super.setup(attributes);
  }
}

finally

This function will be called on teardown. Can be useful for setting css-classes.

Eg.

import { IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  finally(attributes: Attributes) {
    // So something
  }
}

isBot

A function to check if the current user is a bot or not. Can be useful for SSR and SEO.

Default function:

import { isPlatformServer } from '@angular/common';
import { IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  isBot(attributes?: Attributes) {
    // Check if the user is a bot or not.
    this.navigator; // Is the same as `window.navigator` if window is defined otherwise undefined.
    isPlatformServer(this.platformId); // True if the code is running on the server
  }
}

Both IntersectionObserverHooks and ScrollHooks will load the image as soon as possble if isBot returns true.

isDisabled

A function to decided if the module should be disabled, meaning: it should not do anything, just exit right away, without loading any image. The default behavior is to disable it on the server if the user is not a bot:

import { isPlatformServer } from '@angular/common';
import { IntersectionObserverHooks } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  isDisabled() {
    // This is the same as: `return super.isDisabled();`
    return isPlatformServer(this.platformId) && !this.isBot();
  }
}

skipLazyLoading

A function to decided if we should load the image right away. This can be useful if you want to skip to lazyload the image when SSR:

import { isPlatformServer } from '@angular/common';
import { IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  skipLazyLoading(attributes: Attributes) {
    return isPlatformServer(this.platformId); 
  }
}

Or maybe you want to load the image ASAP from specific domains

import { IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  skipLazyLoading(attributes: Attributes) {
    const imageUrl = new URL(attributes.imagePath);
    return imageUrl.hostname === 'example.org';
  }
}

The default behavior for skipLazyLoading is to call isBot. Meaning: if the user is a bot, load the image right away, otherwise, lazyload the image.

onAttributeChange

This function is called when some of the atrebute of the image is changed.

import { IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  onAttributeChange(newAttributes: Attributes) {
    console.log(`New attributes: ${newAttributes}`);
  }
}

onDestroy

This function is called when a image is loaded and the directive will unmount, aka. when ngOnDestroy is called in the directive. This can be useful if you want to do some cleanup.

import { IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  imageToBeLoaded = new Map<string, Attributes>();

  onAttributeChange(newAttributes: Attributes) {
    console.log(`New attributes: ${newAttributes}`);
    imageToBeLoaded.set(newAttributes.id, newAttributes);
  }

  onDestroy(attributes: Attributes) {
    imageToBeLoaded.delete(attributes.id);
  }
}

πŸ”Ž Search Engine Optimization (SEO)

ng-lazyload-image are using the following strategy by default:

Server side rendering (SSR)

If the incoming request is from a bot; it will set [lazyLoad] to src on the image (letting the browser loading the image right away). Useful if the bot don't understand javascript.

If the request is not from a bot (or if we can't decide), don't do anything and let the client fix the images (see below).

You can chang this behavior by implementing your own skipLazyLoading function (see skipLazyLoading above). Let's say you always want to show the image ASAP for SSR, regardles of if the user is a bot or not:

import { isPlatformServer } from '@angular/common';
import { IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  skipLazyLoading(attributes: Attributes) {
    // Skipping lazyloading the image for SSR
    return isPlatformServer(this.platformId); 
  }
}

Client side

  • If the user is a bot (see isBot hook above), render all the images right away. (useful if the bot understand javascript)
  • If the user is not a bot (or if we can't decide), lazy load the images

πŸ€” FAQ

Q How can I manually trigger the loading of images?

A You can either use the getObservable hook if you can trigger the loading outside the dom or you can use the customObservable input, see Custom Observable

Q Does this library work with ionic or some other wrapper for Angular?

A Yes, but ionic and some other library wraps the whole document inside an other div so you might need to create your own scroll listener.

Q How can I add a transition effect between the default image and the lazy loaded image?

A See: #300

Q It doesn't work with BrowserAnimationsModule

A Are you using the scroll preset? If so, take a look at this issue.

Q Can I add a debounce time before loading the image?

A Yes, take a look at this issue.

Q Can I cancel image loading when the user change page?

A Yes, take a look at this issue.

Q I can't get it to work. Can you help me?

A Sure, create an issue and describe your issue in as much detail as possible.

πŸ™‡β€ Contributing

See the contributing guide

ng-lazyload-image's People

Contributors

cristianmartinez avatar csbok avatar dependabot[bot] avatar dhardtke avatar diogoqueiros avatar felipefialho avatar freezing avatar greenkeeper[bot] avatar greenkeeperio-bot avatar intellix avatar jonnyprof avatar kevinbuhmann avatar kp42 avatar oskarkivra avatar pbartrina avatar rimlin avatar sapierens avatar ssuperczynski avatar stu01509 avatar tjoskar avatar vaidiep avatar varrocs avatar writer0713 avatar zieka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng-lazyload-image's Issues

Lazy load is not triggered when data is filtered

Hello - thanks for the library. I'm having challenges with one specific use case.

We have a header, with an input box, and a content area with a PrimeNG datagrid. The datagrid is wrapped in a DIV with overflow-y set to auto. The input text gets fed to a PipeTransform which does a filter(...) on the datagrid's collection.

Everything works as expected if we have no filter set... scrolling up and down on the DIV (scrollTarget) lazily loads the images. The issue is when we start keying in a filter. The grid filters the list of entries down, and entries that were on the bottom of the list (no image loaded yet) begin to show up, but their image never loads.

I suspect it's because the DIV never actually scrolled, it resized as the items inside it grew and shrank... and eventually it shrank to the point that no scrollbar was needed so the scrollbar disappeared.

Code sample below... thanks!

<div id="navigationContainer" class="flexContainer">
  <div id="navigationHeader" class="navigationHeader">
    <input 
      pInputText 
      id="txtTtn" 
      type="text" 
      [(ngModel)]="navigationFilter" 
      (keyup.enter)="onEnterKey($event)"
      placeholder="{{'global.typeToNarrow'|translate}}"
      />
  </div>

  <div #graphicalNavigationScroller class="ui-g-nopad" style="overflow-y: auto">
    <p-dataGrid 
      id="navGrid"
      [value]="currentNavigationNode.childNodes | navigationFilterPipe: navigationFilter">
      
      <template let-navigationChildNode>
        <div class="ui-g-12 ui-md-3 ui-lg-2" [ngStyle]="{'min-width' : currentNavigationNode.childLevelIllustrationWidth+25+'px' }">
          <a class="thumbnail" (click)="navigate(navigationChildNode)" title="{{navigationChildNode.name}}">
            <img
              [scrollTarget]="graphicalNavigationScroller"
              [lazyLoad]="someSecretURL"
              width="{{currentNavigationNode.childLevelIllustrationWidth}}"
              height="{{currentNavigationNode.childLevelIllustrationHeight}}"
              />
            <div>{{navigationChildNode.name}}</div>
          </a>
        </div>
      </template>
    </p-dataGrid>
  </div>
</div>

image not loaded before scroll starts ionic 2

hello
i am using this library with ionic 2 rc3
everything works great except when a page is shown images are not loaded until i scroll.
even after a tiny scrolling images in the viewport start to show as expected.
here is my template

<ion-content #container>
	<ion-list>
		<button ion-item detail-none (click)="Action(playlistItem)" *ngFor="let playlistItem of playlistMatched" >
		<ion-thumbnail item-left>
			<img src="assets/img/icon.png" [lazyLoad]="playlistItem?.track.album.images[2].url" [scrollTarget]="container.getScrollElement()" >
		</ion-thumbnail>
		</button>
	</ion-list>
</ion-content>

ParseError: 'import' and 'export' may appear only with 'sourceType: module'

Hello!
I'm working with Angular 2 on an Ionic 2 project and I'm trying to import LazyLoad but I get a compile error

my_file.js
import {Component, Input} from "angular2/core";
import {LazyLoadImageDirective} from "ng2-lazyload-image/index";

@Component({
    selector: 'image',
    template: `
        <img src="images/placeholder_big" [lazyLoad]="image" offset="50">
    `,
    directives: [LazyLoadImageDirective]
})
class ImageComponent {
    @Input('src') image;
}
export {ImageComponent}
/Users/lobetia/repo/ionic2_migration/node_modules/ng2-lazyload-image/index.ts:1
import {LazyLoadImageDirective} from './src/lazyload-image.directive';
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

Trying to include the module without /index writing
import {LazyLoadImageDirective} from "ng2-lazyload-image";
I get a similar error

/Users/lobetia/repo/ionic2_migration/node_modules/ng2-lazyload-image/src/lazyload-image.directive.ts:1
import 'rxjs/add/observable/fromEvent';
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

I don't know how to fix this and I can't figure out if is a my problem o somethings related to this module.

Can you help me 😰 ? Thank you

An in-range update of @angular/common is breaking the build 🚨

Version 2.2.3 of @angular/common just got published.

Branch Build failing 🚨
Dependency @angular/common
Current Version 2.2.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/common is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Provide changelog

Hi @tjoskar, Great module πŸ‘, Can you provide Changelog file for future updates?

I would like to prepare a PR to add window.service.ts, window.service.spec.ts and Universal support

An in-range update of @angular/platform-server is breaking the build 🚨

Version 2.2.3 of @angular/platform-server just got published.

Branch Build failing 🚨
Dependency @angular/platform-server
Current Version 2.2.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/platform-server is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of @angular/core is breaking the build 🚨

Version 2.2.3 of @angular/core just got published.

Branch Build failing 🚨
Dependency @angular/core
Current Version 2.2.2
Type peerDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/core is β€œonly” a peerDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Lazy Loading inside a Scrollable area

Thanks for this wonderful library. I cannot get it to work with scrollable div unfortunately.

Using this below code doesn't works.

scrollTarget = this.document.getElementById('scrollableDiv');

Any light on how I can use the config in better way?

An example would have been great though.

P.S: I am not using ionic.

An in-range update of @types/core-js is breaking the build 🚨

Version 0.9.35 of @types/core-js just got published.

Branch Build failing 🚨
Dependency @types/core-js
Current Version 0.9.34
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @types/core-js is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Warning:Don't reference this project as serious performance issues

After use this project, the changedetector of whole app will run change detection ceaselessly.
This will cause a serious performance issue to whole app.

<img src="/image/imgLazyLoad.png" [lazyLoad]="showcase.logo"
[offset]="1200" (click)="goShowcaseDetail(showcase)"
[scrollTarget]="homeContainer.getScrollElement()"
/>

_20161229142554

Problem importing LazyLoadImageDirective

Hi,

I had a problem importing the directive in my ts file.

In the usage block ("https://github.com/tjoskar/ng2-lazyload-image#usages"), you say to import like the line below, but It did not work on my project:
import { LazyLoadImageDirective } from 'ng2-lazyload-image';

It worked for me when I imported using the line below, using the same import pattern you have used in your example:
import { LazyLoadImageDirective } from 'ng2-lazyload-image/src/lazyload-image.directive';

Do you think I am doing something wrong?

Thanks,
Ricardo

An in-range update of typescript is breaking the build 🚨

Version 2.1.4 of typescript just got published.

Branch Build failing 🚨
Dependency typescript
Current Version 2.1.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As typescript is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Commits

The new version differs by 745 commits .

  • 409311f Update LKG
  • e15166a Merge pull request #12670 from Microsoft/mergeMaster1205
  • ae3b6e7 Merge branch 'master' into release-2.1
  • 5c71de1 Merge pull request #12652 from Microsoft/fixIndexedAccessWithAny
  • ee172cf Accept new baselines
  • 95aed3f Add regression test
  • c52eb6c Indexed access any[K] has type any
  • b7e8a6d Merge pull request #12643 from Microsoft/keyofUnionIntersection
  • 23992ba Merge pull request #12640 from Microsoft/mappedTypesSecondaryInferences
  • 3aa05b2 Accept new baselines
  • b4836e3 Add tests
  • b876211 Property handle union/intersection types in type variable checks
  • f61a224 Merge pull request #12639 from MattiasBuelens/fixElideFallthrough
  • 970c4aa Accept new baselines
  • 773c9a7 Add tests

There are 250 commits in total. See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Ionic2 custom component

If I have custom angular2 component, for example custom user card, then all lazyload images loads instanly. For example there is a page with scrollable area and 100 user card components, when I open the page all lazyload images loads immediately, but it should load only then I scroll to them.

An in-range update of webpack is breaking the build 🚨

Version 1.14.0 of webpack just got published.

Branch Build failing 🚨
Dependency webpack
Current Version 1.13.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As webpack is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Release Notes v1.14.0

Bugfixes:

  • fix this context for AMD require when combined with async commons chunk
  • update core dependency, which fixes a SourceMap bug
  • update node.js core libs
Commits

The new version differs by 10 commits .

  • e666686 1.14.0
  • 6859bdd update webpack-core dependency
  • 50c0220 Merge pull request #3386 from chuckdumont/webpack-1
  • 938dc66 Update unit test to use CommonsChunkPlugin
  • 132272b Update unit test to use CommonsChunkPlugin
  • fd43f11 Update unit test per review comments
  • d46663e Initial stab at unit test
  • 6b733fd Fix lost context when invoking require()
  • 5a56be9 Merge pull request #3368 from webpack/update/node-libs-browser
  • c1d6ed8 Update node-libs-browser@^0.7.0 and backport changes from webpack-2 to NodeSourcePlugin

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

window is undefined in Angular 2 Universal

Hello,

I am using your module with Angular 2 Universal, meaning that the app is rendered on the server.

When your module is rendered, the window is undefined because it's being rendered by node. It would great if it could check wether or not the module is being rendered by a browser or server.

Cheers

Doesn't load dynamically added images

For example I have list of comments where each comment consists of image, name, lastname, comment, date. When I open page and scroll down everything is ok images are lazyloaded, but when I insert comment dynamically image doesn't load but has class "ng2-lazyloaded"

localhost_8100 - google chrome 2017-02-02 17 09 46

An in-range update of @angular/platform-browser is breaking the build 🚨

Version 2.2.0 of @angular/platform-browser just got published.

Branch Build failing 🚨
Dependency @angular/platform-browser
Current Version 2.1.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/platform-browser is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Images not loading inside of a carousel

Hey,

Thanks for developing this awesome module.

I'm running into a small issue where images that are outside of a carousel viewport are not lazy loaded, until the page is scrolled vertically. The carousel (Flickity) is using translate3d for the scrolling so I don't think the scrollTarget will help here.

This is what the component looks like when it's first loaded - The lazy loading is working perfectly.
https://s30.postimg.org/fk7qt0nq9/inital.png

However when you move the carousel to show more items, the new items that were once off the canvas have not been lazy loaded
https://s30.postimg.org/ww83egh7l/carousel_scrolled.png

If you scroll vertically, after moving the carousel to show more items, the images will lazy load.

Is there a way to load all of these images at once, even if they are horizontally off the canvas?

Cheers!

Use error image if http request fails rather than default image

I think that this directive should include one more input, something like [errorImage].

The idea behind this is to have loader image, e.g. "loading.gif" as default image.
Lazily loaded image should be the one we want. However, this image might not exist or the http request might fail, which is out of our control. Currently, if http request fails, it will use default image (the one that is specified in src), but that is bad if we wanted to show loader image initially.

I might be wrong here and don't see the correct way to do. If that is the case please correct me?

Otherwise, would you mind adding a new input to the directive, i.e. "errorImage" where the behavior should stay as it is at the moment if errorImage is null, otherwise it should use errorImage if http request fails.

Input example would be:

<img [src]="loader.gif" [lazyLoad]="our_goal_img.png" [errorImg]="no_image.png" offset="100" />

PixelateImage input feature

I tried to implement pixelateImage example but I want it to be removed when lazyLoad loads, is it possible to implment @Input() pixelateImage in the directive to display it and to remove it when lazyLoad image is loaded?

Ionic2

I need to use your plugin with cordoca/ionic2 typescript app, When trying to add the providers i am getting this error, Parse Error: 'import' and 'export' may appear only with 'sourceType: module'

Could you please help in how i can use it with ionic2 typescript.

An in-range update of electron-prebuilt is breaking the build 🚨

Version 1.4.9 of electron-prebuilt just got published.

Branch Build failing 🚨
Dependency electron-prebuilt
Current Version 1.4.8
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As electron-prebuilt is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Release Notes v1.4.9

1.4.9

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of @types/node is breaking the build 🚨

Version 6.0.53 of @types/node just got published.

Branch Build failing 🚨
Dependency @types/node
Current Version 6.0.52
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @types/node is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of protractor is breaking the build 🚨

Version 4.0.12 of protractor just got published.

Branch Build failing 🚨
Dependency protractor
Current Version 4.0.11
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As protractor is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Commits

The new version differs by 16 commits .

  • 81a6eaa docs(element): fix docs for element(locator).then
  • 7f443c7 chore(release): Version bump and changelog for 4.0.12
  • 50c29ac chore(scripts): clean up package scripts (#3794)
  • 4449112 chore(cleanup): jshint cleanup for spec (#3800)
  • 742f264 fix(driverProviders): quit forked instances w/ local driver provider (#3787)
  • 7d481d6 fix(ExpectedConditions): non-static ExpectedConditions for browser (#3766)
  • 12c5139 docs(website): improve docs for $ and $$ (#3773)
  • 6193728 chore(tests): Testapp with @angular/upgrade/static (ngUpgrade for AoT apps) (#3758)
  • 19f99d6 chore(browser): fix typings for getCapabilities (#3742)
  • 70bc6ea chore(refactor): prefer path.resolve (#3751)
  • 40eb493 chore(docs): update docs to use webdriver-manager for mobile setup (#3320)
  • f773f5f chore(testapp): upgrade angular 2 versions (#3746)
  • 9fdd3d3 chore(npm): add some artifacts to npmignore (#3747)
  • 10d84ff chore(types): make TS think that ElementArrayFinder and ElementFinder are compatible with WebElement (#3732)
  • f4843d1 cleanup(types): Fix webelement.then() return type. (#3739)

There are 16 commits in total. See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of @angular/core is breaking the build 🚨

Version 2.4.1 of @angular/core just got published.

Branch Build failing 🚨
Dependency @angular/core
Current Version 2.4.0
Type peerDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/core is β€œonly” a peerDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

<image> selector not working in IE11 and Edge

This is not really an issue per se, but I wanted to document this here for others, and maybe the docs will be updated to reflect this.

It appears that IE11 and Microsoft Edge browsers are not playing well with having image as a selector. After implementing the example code and using <image ...></image> I tested in these 2 browsers and saw no images displayed (they were requested by the browsers however). This behaviour happens also on demo page.

Checking the Dev Tools (F12) I noticed that <image> tags were rewritten as <img> tags, not sure why.

I updated the component to use a different selector. I picked <lz-image> and this eliminates the issue in these 2 browsers.

An in-range update of simple-spy is breaking the build 🚨

Version 2.1.0 of simple-spy just got published.

Branch Build failing 🚨
Dependency simple-spy
Current Version 2.0.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As simple-spy is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Commits

The new version differs by 5 commits .

  • d01e92c 2.1.0
  • dffa099 Merge pull request #7 from mightyiam/constructor
  • 9b42755 Can be used as constructor
  • 2d54bb9 Merge pull request #6 from tjoskar/greenkeeper/nyc-10.0.0
  • 5389159 chore(package): update nyc to version 10.0.0

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of @types/node is breaking the build 🚨

Version 6.0.49 of @types/node just got published.

Branch Build failing 🚨
Dependency @types/node
Current Version 6.0.48
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @types/node is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Ionic Build :: Property '_el' is private

Hi,

this is awesome when I serve my Project, but when I am trying to build then facing this issue.

Property '_el' is private and only accessible within class 'ScrollView'.

Code example as below.

<ion-content #container>
<div>
<div class="bootstrap-row">
<div class="col col-50" *ngFor="let product of products">
<img *ngIf="container._scroll._el.offsetParent !== null" [lazyLoad]="imagePath+product.image" src="img/others/load-product-thumb.png" [scrollTarget]="container._scroll._el">
</div>
</div>
</div>
</ion-content>

An in-range update of @angular/compiler-cli is breaking the build 🚨

Version 2.4.1 of @angular/compiler-cli just got published.

Branch Build failing 🚨
Dependency @angular/compiler-cli
Current Version 2.4.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler-cli is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Ionic2 content init working, load image window scroll event not triggering

I'm trying to use your directive inside an ng2-ion2 project and it seems the scroll event is not being triggered. I've looked in your source code and it seems to me that the observable event is not being triggered. I think Observable.fromEvent(window, 'scroll') should be adjusted to an Ionic2 scroll event to make it work.

Reproduce

  1. Install & import directive (Ionic2 project)
  2. Template: <img [src]="defaultImage" [lazyLoad]="image" [offset]="offset">
  3. Class constructor:
this.defaultImage = 'https://www.placecage.com/1000/1000';
this.image = 'https://images.unsplash.com/photo-1443890923422-7819ed4101c0?fm=jpg';
this.offset = 100;

Result

Initial default images are being shown, the lazyload images are not loaded, so that's working.
But the scroll event is not being triggered so lazyloading new images is not working in Ionic2.

Thank you.

Consuming output of build

Hello

'npm run build:example' produces the dist folder.

Shouldn't there be an output generated which can be deployed on a static server, i.e., a folder containing index.html, the transpiled JS files and the resources folder?

Protractor Timeouts

When running protractor test they will timeout on any component using the lazy load directive. Protractor watches the ngZone to know when pending xhr calls, timeouts and intervals are completed before running.
In the scroll-listener.ts the .sampleTime(100, scheduler) creates a interval that wont ever end during a protractor test. I found a way arount this by the adding the following code to the directive

ngAfterContentInit() {
    this.ngZone.runOutsideAngular(() => { // run outside angular
      this.scrollSubscription = getScrollListener(this._scrollTarget)
        .filter(() => this.isVisible())
        .take(1)
        .switchMap(() => this.loadImage(this.lazyImage))
        .do(() => this.setImage(this.lazyImage))
        .finally(() => this.setLoadedStyle())
        .subscribe(() => this.ngOnDestroy(),
        error => {
          this.setImage(this.errorImg || this.defaultImg);
          this.ngOnDestroy();
        });
    });
  }

According to this https://github.com/angular/protractor/issues/3349#issuecomment-232253059 Protractor watches the main ngZone so if we run the interval out of it protractor run successfully. I'm not sure how this would work with the protractor tests on this project but I can try to make a pull request when I get the chance.

CSS Class for yet to be Loaded Items

We use the following CSS to create fade-in effect for lazy loaded images.

img {
    transition: opacity 1s;
    opacity: 0;
}
img.ng2-lazyloaded {
    opacity: 1;
}

Unfortunately, this will cause all images inside the component to be hidden unless lazy loaded using ng2-lazyload. Sometimes, it is not really necessary to lazy load small images such as logos and sprites. Can we have a CSS class on yet to be loaded images, maybe ng2-loading, so we can have the fading effect like this:

img.ng2-lazyloading {
    transition: opacity 1s;
    opacity: 0;
}
img.ng2-lazyloaded {
    opacity: 1;
}

Can't bind to 'lazyload' since it isn't a known native property

I'm running an existing Ionic 2 project (2.0.0-beta.11, using Angular 2.0.0-rc.4). Installed and setup, but keep getting the following error (The error occurs on runtime. No issue when compiling)

image

Steps I took:

Ran Npm:
$ npm install ng2-lazyload-image --save

Imported into my component:
import { LazyLoadImageDirective } from 'ng2-lazyload-image';

Set Directives:
directives: [ LazyLoadImageDirective ]

Set variables and defaults:

export class PostComponent {
defaultImage: any = 'build/assets/preloader.gif';
offset = 100;
@Input() feedImage: string = 'build/assets/blank-default-feed-bg.png';
}

In my template:
<img [src]="defaultImage" [lazyload]="feedImage" [offset]="offset" class="feed-image">

Maybe there's something I'm overlooking, but I can't seem to see what it is.

An in-range update of @angular/compiler is breaking the build 🚨

Version 2.2.0 of @angular/compiler just got published.

Branch Build failing 🚨
Dependency @angular/compiler
Current Version 2.1.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of @angular/compiler-cli is breaking the build 🚨

Version 2.3.0 of @angular/compiler-cli just got published.

Branch Build failing 🚨
Dependency @angular/compiler-cli
Current Version 2.2.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler-cli is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of karma-mocha is breaking the build 🚨

Version 1.3.0 of karma-mocha just got published.

Branch Build failing 🚨
Dependency karma-mocha
Current Version 1.2.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As karma-mocha is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Commits

The new version differs by 12 commits .

  • e39c323 chore: release v1.3.0
  • f3a114d chore: update contributors
  • eadaee0 Merge pull request #123 from maksimr/karma-mocha-103
  • a21c2b2 chore: Add Changelog.md
  • b6af3eb Merge pull request #121 from maksimr/mocha-opts
  • 11a0dd8 feat: support mocha opts
  • e8ff71f Merge pull request #120 from maksimr/master
  • 30bbe29 chore: add tests for lib files
  • 0bbf932 fix(deps): remove peer dependency on mocha
  • 65a93d7 Merge pull request #119 from boneskull/travis-node-fix
  • 5213d5f chore(ci): fix node v0.10 version in build matrix
  • 246f25a fix: polyfill Date.now to restore IE compat

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Error image class

Would be nice to add a class indicating that there was an error loading image.

An in-range update of @angular/platform-browser-dynamic is breaking the build 🚨

Version 2.3.0 of @angular/platform-browser-dynamic just got published.

Branch Build failing 🚨
Dependency @angular/platform-browser-dynamic
Current Version 2.2.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/platform-browser-dynamic is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

default Image is not visible

I have added the default Image as well the lazyload image path .
Did not get anything visible until the lazyload Image loaded.
Same as on the example

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.