|
1 | 1 | import { Component, Input, Output, ElementRef, Renderer, OnInit, EventEmitter } from '@angular/core';
|
2 | 2 | import { ImageLoader } from '../providers/image-loader';
|
3 | 3 | import { ImageLoaderConfig } from '../providers/image-loader-config';
|
| 4 | +import { File } from '@ionic-native/file'; |
4 | 5 |
|
5 | 6 | @Component({
|
6 | 7 | selector: 'img-loader',
|
@@ -113,15 +114,15 @@ export class ImgLoader implements OnInit {
|
113 | 114 |
|
114 | 115 | element: HTMLElement;
|
115 | 116 |
|
116 |
| - constructor( |
117 |
| - private _element: ElementRef |
118 |
| - , private _renderer: Renderer |
119 |
| - , private _imageLoader: ImageLoader |
120 |
| - , private _config: ImageLoaderConfig |
121 |
| - ) { } |
| 117 | + constructor(private _element: ElementRef, |
| 118 | + private _renderer: Renderer, |
| 119 | + private _imageLoader: ImageLoader, |
| 120 | + private _config: ImageLoaderConfig, |
| 121 | + private _file: File) { |
| 122 | + } |
122 | 123 |
|
123 | 124 | ngOnInit(): void {
|
124 |
| - if(this.fallbackAsPlaceholder && this.fallbackUrl) { |
| 125 | + if (this.fallbackAsPlaceholder && this.fallbackUrl) { |
125 | 126 | this.setImage(this.fallbackUrl, false);
|
126 | 127 | }
|
127 | 128 |
|
@@ -186,7 +187,10 @@ export class ImgLoader implements OnInit {
|
186 | 187 | }
|
187 | 188 |
|
188 | 189 | // set it's src
|
189 |
| - this._renderer.setElementAttribute(this.element, 'src', imageUrl); |
| 190 | + this._file.resolveLocalFilesystemUrl(imageUrl).then((entry) => { |
| 191 | + this._renderer.setElementAttribute(this.element, 'src', entry.toInternalURL()); |
| 192 | + }); |
| 193 | + |
190 | 194 |
|
191 | 195 | if (this.fallbackUrl && !this._imageLoader.nativeAvailable) {
|
192 | 196 | this._renderer.setElementAttribute(this.element, 'onerror', `this.src="${ this.fallbackUrl }"`);
|
@@ -218,8 +222,9 @@ export class ImgLoader implements OnInit {
|
218 | 222 | this._renderer.setElementStyle(this.element, 'background-repeat', this.backgroundRepeat);
|
219 | 223 | }
|
220 | 224 |
|
221 |
| - this._renderer.setElementStyle(this.element, 'background-image', 'url(\'' + ( imageUrl || this.fallbackUrl ) + '\')'); |
222 |
| - |
| 225 | + this._file.resolveLocalFilesystemUrl(imageUrl).then((entry) => { |
| 226 | + this._renderer.setElementStyle(this.element, 'background-image', 'url(\'' + ( entry.toInternalURL() || this.fallbackUrl ) + '\')'); |
| 227 | + }); |
223 | 228 | }
|
224 | 229 |
|
225 | 230 | this.load.emit(this);
|
|
0 commit comments