Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
Conditional is not working as expected?

I have this two components:

<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>

First one have master and second one not.

What i want is to set condtional to disabled buttons if its not master and if action.name !=='create':

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

But problem is that is not working i get for first component all buttons enabled, and for second first is enabled. Any suggestion?

 <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:

  "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"}
        ],
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

I don't know if I correctly get it but, for you second component:

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

We know that master=false then !master=true. When we are on the button "create", action.name =='create' is true then action.name !== 'create' is false.

We have true && false = false so it's normal that your button is not disabled.

I don't know if it's what you want but if you only want to display the button create on master, you can put:

[disabled]="(!master) || ((!master) && (action.name !== 'create'))"
over 4 years ago · Santiago Trujillo Denunciar

0

Documentation of bootstrap says if you want to disable a button you should use it as disabled="disabled" where as you are setting it as true or false..

Use a function to achieve this as

<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>

Code

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

LIVE DEMO

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda