How do I avoid the click event if it does not? - Angular

1

I have this button in Angular, that even if I have it disconnected, I open the file explorer, I usually do it is

<miBoton (click)="estaDesamblado?'':miEventoClick()" >

Some correct way to solve it

#abrirArchivo{
  display: none;
}

label{
  padding: 5px;
  cursor: poiter;
  background-color: #333;
  color: #fff;
}

label[disabled]{
  background-color: #ddd;
}
<label for="abrirArchivo" disabled>Abrir</label>
<input id="abrirArchivo" type="file">
    
asked by Samir Llorente 20.06.2018 в 17:18
source

2 answers

2

Why not pass the logic to the component, instead of leaving it in the template? Just do not do anything when it does not correspond.

miEventoClick() {
  if (!this.estaDesamblado) {
    ...
  }
}
    
answered by 20.06.2018 в 17:34
1

With the property of angular disabled you prevent them from clicking or interacting with the element:

<miBoton (click)="miEventoClick()" [disabled]="estaDesamblado" >

Or you could handle the logic in the function as a previous answer says but I would use something else

<miBoton (click)="miEventoClick($event)">

And in the function:

miEventoClick(event){
 event.preventDefault();
 if(!this.estaDesamblado){
   // Hacer algo
 }
}
    
answered by 28.06.2018 в 00:16