2017-10-05 92 views
0

我想檢測一下,如果我點擊裏面的組件,但我有一些地方,我用ngIf來顯示或隱藏一些元素,這就是問題,因爲它看不到那個元素,我現在得到錯誤。任何建議如何解決這個問題?我有側邊欄組件。側邊欄裏面我有這樣的:組件內檢測是否對某些元素有ngIf?

<default-block head="Podaci o korisniku" class="z-col-24" block="blockgroup" [(visible)]="isCustomerVisible || getFromModal" [mainBlock] = "isVisibleBackCa" [additionalItems]="true" (buttonClick)="getFromHistory()" 
         (openModal)="showModal($event)" [ngClass]="{disabledCa: disabled}"> 


         <div default-block="body" class="contact-body pointer"> 
          <div class="contact-body-wrapper" dnd-draggable [dragData]="customerGeneralInfo" (onDragStart)="dnd.set(true);" (onDragEnd)="dnd.set(false)" > 
           <span class="inline" *ngIf="customerGeneralInfo?.customerinfo?.lastname"> 
            <div class="z-inputs" > 
             <label>Korisnik</label> 
             <span disabled class="textarea"> {{customerGeneralInfo?.customerinfo?.lastname}} </span> 
            </div> 
           </span> 
           <span class="inline" *ngIf="customerGeneralInfo?.customertypeName"> 
            <div class="z-inputs"> 
             <label>Tip</label> 
             <input class="readonly" [ngModel]="customerGeneralInfo?.customertypeName" type="text" disabled> 
            </div> 
           </span> 
           <span class="inline" *ngIf="customerGeneralInfo?.customerstypeName"> 
            <div class="z-inputs"> 
             <label>Podtip</label> 
             <span class="textarea">{{customerGeneralInfo?.customerstypeName}}</span> 
            </div> 
           </span> 
           <span class="inline" *ngIf="customerGeneralInfo?.parentName"> 
            <div class="z-inputs"> 
             <label>Parent</label> 
             <span class="textarea" disabled>{{customerGeneralInfo?.parentName}}</span> 
            </div> 
           </span> 
           <span class="inline" *ngIf="customerGeneralInfo?.headName"> 
            <div class="z-inputs"> 
             <label>Nosilac hijerarhije</label> 
             <span class="textarea" disabled >{{customerGeneralInfo?.headName}}</span> 
            </div> 
           </span> 
           <span class="inline" *ngIf="customerGeneralInfo?.activationdate"> 
            <div class="z-inputs"> 
             <label>Datum aktivacije korisnika</label> 
             <input class="readonly" [ngModel]="customerGeneralInfo?.activationdate | date:'dd.MM.yyyy'" type="text" disabled> 
            </div> 
           </span> 
           <span class="inline" *ngIf="customerGeneralInfo?.terminationdate"> 
            <div class="z-inputs"> 
             <label>Datum isključenja korisnika</label> 
             <input class="readonly" [ngModel]="customerGeneralInfo?.terminationdate | date:'dd.MM.yyyy'" type="text" disabled> 
            </div> 
           </span> 
           <span class="inline" *ngIf="customerGeneralInfo?.description"> 
            <div class="z-inputs"> 
             <label>Razlog isključenja korisnika</label> 
             <input class="readonly" [ngModel]="customerGeneralInfo?.description" type="text" disabled> 
            </div> 
           </span> 
          </div> 
</default-block> 

我有這個<default-block>在那裏我有與ngIf作品可見真或假的多。現在當我點擊邊欄上的somem meni時,我會在邊欄組件中顯示該塊。問題是當我在這些塊之間切換時,因爲它們是隱藏的event.target是假的,然後它總是檢測到「外部」事件。

回答

0

使用@ViewChild for elemen refs。示例和用法here

+0

如果我已經在該組件上,該如何幫助我? – None

+0

感謝您的更新。乍一看,嘗試使用* ngIf而不是Visible屬性:這是[不推薦](http://angularjs.blogspot.hu/2016/04/5-rookie-mistakes-to-avoid-with-angular。 HTML)在Angular中了。也許不會混合它們將解決問題。 – ForestG

+0

可見只是輸入,然後在該組件上使用隱藏類,我隱藏或顯示..與顯示:沒有像ngIf一樣 – None