Search code examples
htmlangularbuttonconditional-statementsnativescript

How can I make a condition in a button in angular?


my idea is that if today's date is greater than or equal to the expected date that the button directs to "x" or "y"...

I don't know where can I put this condition (if on file .ts or .html):

var expectedDate = new Date ("2022/08/11")
var dates = expectedDate.toString()
var today = new Date().toISOString().split('T')[0];
if(today >= expectedDate) {
 microsoftLogin()
}
else{...
googleLogin()
}

Here is my code in .HTML where is my button Login I don't know if is possible to add the condition on (tap)

<Button 
width="70%" 
height="40" 
(tap)="CONDITION HERE"
text="Iniciar sesión" 
class="login-submit" 
row="2">
</Button>

Solution

  • I don't know much about native script but you should be able to make a method in your TS file and call it in the HTML

    loginTapped() {
     var expectedDate = new Date ("2022/08/11")
     var dates = expectedDate.toString()
     var today = new Date().toISOString().split('T')[0];
     if(today >= expectedDate) {
      microsoftLogin()
     }
     else{...
     googleLogin()
     }
    }
    <Button 
    width="70%" 
    height="40" 
    (tap)="loginTapped()"
    text="Iniciar sesión" 
    class="login-submit" 
    row="2">
    </Button>

    Hopefully this helps.