*ngIf with Boolean

Asked

Viewed 428 times

1

I have a boolean argument on a *ngIf, however it does not seem to work. If the argument is true:

<ion-input type="text" *ngIf="produto.fracionado"  value="Sim" readonly></ion-input>

If the argument is false:

<ion-input type="text" *ngIf="!produto.fracionado" value="Não" readonly></ion-input>

However it is always returned me "Yes", even for cases of false argument.

  • It seems to work (https://jsbin.com/yoqufoceva/edit?html,js,output). Make sure that Angular is loaded correctly on the page?

  • I am sure because the rest of the page works correctly. It was missing to say that I am using Ionic and Angular 3.1.1.

  • Sorry for the error, the core of Angular is 4.0.2.

2 answers

0

if the result you are receiving is "Não" then he will always return true for "Não" is a string valid you need to work the boolean variables always with false and true, or 0 and 1

0

Your html is correct. You can show me the result of your object. I did a simulation on my project with Ionic 3 in this way:

public produto: object = {
    fracionado: false
}

Browser other questions tagged

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