2017-09-12 86 views
0

不工作我有一個div結構是這樣的:基本上在我設置showDragDrop =假hideWindow()方法事件傳播史中angular4

<div [ngClass]="showDragDrop == true ? 'show' : 'fade' " 
         (click)="hideWindow($event); $event.stopPropagation()"> 
    <input type="file" (change)="uploadFile($event)" .../> 
</div> 

,這使得我的div來獲得隱藏。

我的問題是,我有一個輸入='文件'按鈕在這個div內,當我點擊它時,它會觸發hideWindow()方法。

我想這

hideWindow(event) {  
    event.stopPropagation(); 
    this.showDragDrop=false; 
    } 

(event)="doSomething($event); $event.stopPropagation()" 

(event)="doSomething($event); false" 

,但它不工作

+0

@yurzui,我正忙着做演示和沒」 t看到你的評論:( – Vega

+1

@Vega沒關係 – yurzui

回答

2

移動event.stopPropagation();輸入的點擊()

<input type="file" (click)="removetheClick($event)" ...> 

removetheClick(event){ 
    event.stopPropagation(); 
} 

Demo

,或者更簡潔的版本,@yurzui建議:

<input type="file" (click)="$event.stopPropagation()" ...>