Skip to content

Commit

Permalink
fix(component): revert to Renderer class to maintain backwards compat…
Browse files Browse the repository at this point in the history
…bility

closes #95
  • Loading branch information
ihadeed committed Sep 7, 2017
1 parent 6c3b20e commit 316fcb9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/components/img-loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, Output, ElementRef, Renderer2, OnInit, EventEmitter } from '@angular/core';
import { Component, Input, Output, ElementRef, Renderer, OnInit, EventEmitter } from '@angular/core';
import { ImageLoader } from '../providers/image-loader';
import { ImageLoaderConfig } from '../providers/image-loader-config';

Expand Down Expand Up @@ -124,7 +124,7 @@ export class ImgLoader implements OnInit {

constructor(
private _element: ElementRef,
private _renderer: Renderer2,
private _renderer: Renderer,
private _imageLoader: ImageLoader,
private _config: ImageLoaderConfig
) {}
Expand Down Expand Up @@ -191,16 +191,15 @@ export class ImgLoader implements OnInit {
// Using <img> tag
if (!this.element) {
// create img element if we dont have one
this.element = this._renderer.createElement('img');
this._renderer.appendChild(this._element.nativeElement, this.element);
this.element = this._renderer.createElement(this._element.nativeElement, 'img');
}

// set it's src
this._renderer.setAttribute(this.element, 'src', imageUrl);
this._renderer.setElementAttribute(this.element, 'src', imageUrl);


if (this.fallbackUrl && !this._imageLoader.nativeAvailable) {
this._renderer.listen(this.element, 'error', () => this._renderer.setAttribute(this.element, 'src', this.fallbackUrl));
this._renderer.listen(this.element, 'error', () => this._renderer.setElementAttribute(this.element, 'src', this.fallbackUrl));
}

} else {
Expand All @@ -211,11 +210,11 @@ export class ImgLoader implements OnInit {

for (let prop in propMap) {
if (this[prop]) {
this._renderer.setStyle(this.element, propMap[prop], this[prop]);
this._renderer.setElementStyle(this.element, propMap[prop], this[prop]);
}
}

this._renderer.setStyle(this.element, 'background-image', 'url(\'' + ( imageUrl || this.fallbackUrl ) + '\')');
this._renderer.setElementStyle(this.element, 'background-image', 'url(\'' + ( imageUrl || this.fallbackUrl ) + '\')');
}

this.load.emit(this);
Expand Down

0 comments on commit 316fcb9

Please sign in to comment.