如何在 angular 中的按钮中设置条件?

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

我的想法是,如果今天的日期大于或等于按钮指向“x”或“y”的预期日期...

我不知道我可以把这个条件放在哪里(如果在文件 .ts 或 .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()
}

这是我在 .HTML 中的代码 我的登录按钮在哪里 我不知道是否可以在 (tap)

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

我不太了解本机脚本,但你应该能够在你的 TS 文件中创建一个方法并在 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>

希望这对您有所帮助。

这可能对您有所帮助。

expectedDate=null;
today=null;

onLogin() {
  this.expectedDate = new Date('2022/01/11');
  this.today =new Date();

  if(this.today.getTime() > this.expectedDate.getTime())
  {
    // today is greater than expected
    this.microsoftLogin()
  }
  else
  {
    // today is less than expected
    this.googleLogin()
  }
}

microsoftLogin()
{
  // some function logic
}

googleLogin()
{
  // some function logic
}
<button 
  width="70%" 
  height="40" 
  (click)="onLogin()"
  class="login-submit" 
  row="2">
  Login
</button>