@@ -15,12 +15,18 @@ export class CloudinaryBackgroundImageDirective implements AfterViewInit {
1515 constructor ( private renderer : Renderer2 , private el : ElementRef , private cloudinary : Cloudinary ) {
1616 }
1717
18+ isBrowser ( ) : boolean {
19+ return typeof window !== 'undefined' ;
20+ }
21+
1822 ngAfterViewInit ( ) {
19- const nativeElement = this . el . nativeElement ;
20- const options = this . cloudinary . toCloudinaryAttributes ( nativeElement . attributes , this . transformations ) ;
21- const imageUrl = this . cloudinary . url ( this . clBackgroundImage , options ) ;
22- this . renderer . setStyle ( nativeElement , 'background-image' , `url('${ imageUrl } ')` ) ;
23- this . renderer . setStyle ( nativeElement , 'background-repeat' , 'no-repeat' ) ;
24- this . renderer . setStyle ( nativeElement , 'background-position' , 'center' ) ;
23+ if ( this . isBrowser ( ) ) {
24+ const nativeElement = this . el . nativeElement ;
25+ const options = this . cloudinary . toCloudinaryAttributes ( nativeElement . attributes , this . transformations ) ;
26+ const imageUrl = this . cloudinary . url ( this . clBackgroundImage , options ) ;
27+ this . renderer . setStyle ( nativeElement , 'background-image' , `url('${ imageUrl } ')` ) ;
28+ this . renderer . setStyle ( nativeElement , 'background-repeat' , 'no-repeat' ) ;
29+ this . renderer . setStyle ( nativeElement , 'background-position' , 'center' ) ;
30+ }
2531 }
2632}
0 commit comments