2017-04-27 57 views
0

我有這樣的兩個組成部分:有條件的工作不正常?

<app-z-grid [master]="true" title="Tip korisnika" *ngIf="showTab('Tip/podtip korisnika') || showTab('Tip korisnika')" [restPath]="'customertype'" (fillDetailParent)="reinit($event)"></app-z-grid> 
    <app-z-grid title="Podtip korisnika" *ngIf="showTab('Tip/podtip korisnika') || showTab('Podtip korisnika')" [path]='"customerclassification/customerstype.json"' [restPath]="'customerstype'" [isDetail]="'customerstype'" [parentName]="'customertypeCode'" ></app-z-grid> 

首先有一個主站和第二個不。

我想要的是設置condtional爲禁用按鈕,如果它不是,如果action.name掌握和==「創造」!

[disabled]="(!master) && (action.name !== 'create')" 

但問題是,不工作我得到第一個組件的所有按鈕啓用,併爲第二優先啓用。任何建議?

<button *ngFor="let action of grid.actions" [disabled]="action.name !== 'create'" name="{{action.name}}" 
        type="submit" class="btn btn-block-container mousePointer" (click)="this[action.callback]('New', grid.actions)" title="{{action.label}}"> 
        <i *ngIf="action.icon" style="color: white !important" class="{{action.icon}}"></i> 
       </button> 

JSON:

如果要禁用一個按鈕,你應該使用它作爲 disabled="disabled"哪裏,你都將其設置爲true或false引導的
"actions":[ 
      {"name":"create","label":"New", "icon":"fa fa-file buttonicon","disabled":false, "callback":"create"}, 
      {"name":"update","label":"Edit", "icon":"fa fa-pencil-square-o buttonicon", "disabled":true, "callback":"edit"}, 
      {"name":"deletemodal","label":"Delete", "icon":"fa fa-trash buttonicon", "disabled":true, "callback":"deletemodal"} 
     ], 
+0

是什麼'master'的和'action'指TI – Aravind

+0

主只是我知道這是模板中的第一個組件,以及我有一些功能的動作..create,編輯,更新,所以我想只顯示創建 – None

+0

我添加了按鈕的HTML它看起來像 – None

回答

1

我不知道如果我正確地得到它,但是,你第二部分:

[disabled]="(!master) && (action.name !== 'create')" 

我們知道,master=false然後!master=true。 當我們在按鈕「創建」,action.name =='create'是真的,然後action.name !== 'create'是錯誤的。

我們有true && false = false所以這是正常的,你的按鈕沒有被禁用。

我不知道這是否是你想要的,但如果你只是想顯示在按鈕上主創造,你可以把:

[disabled]="(!master) || ((!master) && (action.name !== 'create'))" 
+0

多數民衆贊成它... tnx :) – None

0

文件說..

使用實現此功能的功能如下

<button *ngFor="let action of data.actions" [disabled]="isDisabled(action)" name="{{action.name}}" 
        type="submit" class="btn btn-block-container mousePointer" (click)="this[action.callback]('New', grid.actions)" title="{{action.label}}"> 
     <i *ngIf="action.icon" style="color: white !important" class="{{action.icon}}"></i> 
     </button> 

代碼

isDisabled(action):boolean{ 
    if(action.name !== 'create'){ 
     return 'disabled' 
    } 
    else return '' 
} 

LIVE DEMO

+0

當你在[禁用] – Powkachu

+0

中放置一個布爾值時,它會工作,它將禁用所有三個按鈕。你嘗試過嗎? – Aravind

+0

我一般在說話,我把布爾值在我的[禁用]屬性,它的工作原理。當你使用'[disabled]'作爲屬性綁定時,你不需要函數 – Powkachu