Disable button in Angular depending on a variable

Asked

Viewed 4,505 times

2

I have a problem, I have a condition at the angle when my situation is PENDING, will disable two button.

$scope.situacaoParcelaPendente = "PENDENTE";

/*ultimo teste*/
if ($scope.resultSimulacao.ticlaa1VO.dscSituacaoParcela == $scope.situacaoParcelaPendente) {
  //disabilitar btnSimular, etc
  $scope.btnSimular.disabled = true;

} else {
  //habilitar btnSimular
  $scope.btnSimular.disabled = false;
}

1 answer

3

You can assign boleanos values to your variable, and on your HTML button you use the property ng-disabled

<input class="btn submit-btn" type="submit" value="Salva" ng-disabled="desabilitaBotao" />

In scopo, you assign true or false for the variable

var desabilitaBotao = $scope.resultSimulacao.ticlaa1VO.dscSituacaoParcela == 'PENDENTE';
$scope.desabilitaBotao = desabilitaBotao;

Whenever the value is true in your variable, the button will be disabled.

  • So you didn’t solve why I have this variable. //$Scope.btnSimular.disabled = true;

  • So Pedro, I’m doing it this way below, but it’s not working. $Scope.situatParcelaPendent = "PENDING"; var habilitaBotao = $Scope.resultSimulacao.ticla1VO.dscSituacaoParcela == situatParcelaPendent ? false : true; $Scope.habilitaBotao = habilitaBotao;

  • You do not need to use another variable, just use a boolean variable in the ng-disabled property as quoted. You tried to do so?

  • You are accessing the second variable in the comparison incorrectly. You declared it so $scope.situacaoParcelaPendente and you’re wearing it like this situacaoParcelaPendente.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.