2017-08-04 21 views
0

イメージをクリックしています。イメージポップアップギャラリーを開いています。ポップアップでイメージズームを適用する必要があります。私はonloadを呼び出すが、ポップアップが開かれていないときにはディレクティブを作成しました。angle2のコンポーネントからボタンのonclickディレクティブを呼び出す方法

ポップアップが来たときにディレクティブを呼び出す方法は?私は以下のようないくつかの条件に基づいて指示を呼び出していますコンポーネントからコンポーネントを呼び出しています

まず、

<div *ngIf="hirusImage; else normalImage " > 
    <div > 
    <div id="seadragon-viewer" nwImageZoom [primaryPicture]="primaryPicture" style="float:left;width:500px;height: 333px;color: #333;"></div> 
    </div> 
</div> 

nwImageZoomは私の指示で、

任意のソリューションが理解されるであろう

答えて

0

ありがとう@HostListenerと@HostBindingのコンセプトを使用して、クリック時にディレクティブを呼び出すことができます。

このコードが役に立ちます 君は。働いていない

import { Directive, HostListener, HostBinding } from '@angular/core' 
 

 
    @Directive({ 
 
     selector:'[nwImageZoom]' 
 
    }) 
 

 
    export class NwImageZoomDirective{ 
 

 
    constructor(){} 
 

 
    // here you can add the css class you want add for zooming for that we use 
 
// isZoom is the variable which decide whether the class will be add or not.] 
 

 
@HostBinding('class.zoom') isZoom=false; 
 

 
    enter code here 
 
// here you can attached the 'toggleZoom' function to @HostListener and the 
 
// inside @HostListener you can pass the Event like-'click' 
 

 
@HostListener('click') toggleZoom(){ 
 
    this.isZoom=!this.isZoom; 
 
}

enter code here 
+0

... 私の質問には、ディレクティブではなく、私はボタンをクリックすると、その後のHTML PISが呼び出したが、そのHTML同じディレクティブから、ページのロード時に初回のみを呼び出しています電話しなければならないが、それは起こっていない.. –

関連する問題