Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Commit

Permalink
feat(directive): use directive on img element
Browse files Browse the repository at this point in the history
close #10
  • Loading branch information
SimonGolms committed Jan 15, 2020
1 parent 5587565 commit b162aad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ElementRef } from '@angular/core';
import { ElementRef, Renderer2 } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { NgxIonicImageViewerDirective } from './ngx-ionic-image-viewer.directive';

describe('NgxIonicImageViewerDirective', () => {
const el: ElementRef = null;
const renderer: Renderer2 = null;
const modalController: ModalController = null;

it('should create an instance', () => {
const directive = new NgxIonicImageViewerDirective(el, modalController);
const directive = new NgxIonicImageViewerDirective(el, renderer, modalController);
expect(directive).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
import { Directive, ElementRef, HostListener, Input, Renderer2, OnInit } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { ViewerModalComponent } from './viewer-modal/viewer-modal.component';

@Directive({
selector: '[ionImgViewer]'
})
export class NgxIonicImageViewerDirective {
constructor(private el: ElementRef, public modalController: ModalController) {}
export class NgxIonicImageViewerDirective implements OnInit {
constructor(private el: ElementRef, private renderer: Renderer2, public modalController: ModalController) {}

@Input() scheme?: string;
@Input() slideOptions?: object;
Expand All @@ -19,6 +19,12 @@ export class NgxIonicImageViewerDirective {
this.viewImage(this.src, this.srcHighRes, this.title, this.text, this.scheme, this.slideOptions);
}

ngOnInit() {
if (!this.el.nativeElement.hasAttribute('src')) {
this.renderer.setAttribute(this.el.nativeElement, 'src', this.src);
}
}

async viewImage(
src: string,
srcHighRes: string = '',
Expand Down

0 comments on commit b162aad

Please sign in to comment.