@@ -4,7 +4,7 @@ import { ImageLoaderConfig } from '../providers/image-loader-config';
4
4
5
5
@Component ( {
6
6
selector : 'img-loader' ,
7
- template : '<ion-spinner *ngIf="spinner && isLoading"></ion-spinner>' ,
7
+ template : '<ion-spinner *ngIf="spinner && isLoading && !fallbackAsPlaceholder "></ion-spinner>' ,
8
8
styles : [ 'ion-spinner { float: none; margin-left: auto; margin-right: auto; display: block; }' ]
9
9
} )
10
10
export class ImgLoader implements OnInit {
@@ -34,6 +34,11 @@ export class ImgLoader implements OnInit {
34
34
*/
35
35
@Input ( ) spinner : boolean = this . _config . spinnerEnabled ;
36
36
37
+ /**
38
+ * Whether to show the fallback image instead of a spinner while the image loads
39
+ */
40
+ @Input ( ) fallbackAsPlaceholder : boolean = this . _config . fallbackAsPlaceholder ;
41
+
37
42
/**
38
43
* Use <img> tag
39
44
*/
@@ -106,12 +111,17 @@ export class ImgLoader implements OnInit {
106
111
) { }
107
112
108
113
ngOnInit ( ) : void {
114
+ if ( this . fallbackAsPlaceholder && this . fallbackUrl ) {
115
+ this . setImage ( this . fallbackUrl , false ) ;
116
+ }
117
+
109
118
if ( ! this . src ) {
110
119
// image url was not passed
111
120
// this can happen when [src] is set to a variable that turned out to be undefined
112
121
// one example could be a list of users with their profile pictures
113
122
// in this case, it would be useful to use the fallback image instead
114
- if ( this . fallbackUrl ) {
123
+ // if fallbackUrl was used as placeholder we do not need to set it again
124
+ if ( ! this . fallbackAsPlaceholder && this . fallbackUrl ) {
115
125
// we're not going to cache the fallback image since it should be locally saved
116
126
this . setImage ( this . fallbackUrl ) ;
117
127
} else {
@@ -153,8 +163,8 @@ export class ImgLoader implements OnInit {
153
163
* Set the image to be displayed
154
164
* @param imageUrl
155
165
*/
156
- private setImage ( imageUrl : string ) : void {
157
- this . isLoading = false ;
166
+ private setImage ( imageUrl : string , stopLoading : boolean = true ) : void {
167
+ this . isLoading = ! stopLoading ;
158
168
159
169
if ( this . _useImg ) {
160
170
0 commit comments