Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 按钮真/假循环_Angular_Typescript - Fatal编程技术网

Angular 按钮真/假循环

Angular 按钮真/假循环,angular,typescript,Angular,Typescript,当我按下下一个按钮时,我会返回一个true状态,当我再次按下它时,它会返回一个false状态,依此类推 myComponent.html <button class="btn btn-outline-primary btn-sm" (click)="actualizarEstado()">Editar</button> 在您的组件中,使用false值初始化estado,然后在下面的函数中写入,以便在查找时获得循环真/假值 mycomponent.ts estado :

当我按下下一个按钮时,我会返回一个
true
状态,当我再次按下它时,它会返回一个
false
状态,依此类推

myComponent.html

<button class="btn btn-outline-primary btn-sm" (click)="actualizarEstado()">Editar</button>

在您的组件中,使用false值初始化estado,然后在下面的函数中写入,以便在查找时获得循环真/假值

mycomponent.ts
estado : boolean = false;

actualizarEstado(){
  return this.estado = !this.estado;
}

您可以很快完成:

在您的组件中:

estado:boolean=false;
在html中:

<button class="btn btn-outline-primary btn-sm"(click)="estado=!estado">Editar</button>
Editar
注意:
当您想在typescript中声明参数时,您必须这样做:
参数名称
然后
类型
然后必须使用
=

像这样:

参数名称:type=something有两种方法

来自控制器的第一种方法

app.component.html

视图级别的2st方法

<button class="btn btn-outline-primary btn-sm" (click)="actualizarEstado()">Editar</button>
app.component.html

<button class="btn btn-outline-primary btn-sm" (click)="actualizarEstado()">Editor</button>
import { Component } from '@angular/core';
@Component({
 selector: 'my-app',
 templateUrl: './app.component.html',
 styleUrls: [ './app.component.css' ]
})

 export class AppComponent  {
 public estado : boolean = false;

  actualizarEstado(){
   return this.estado = !this.estado;
  }
}
<button class="btn btn-outline-primary btn-sm"(click)="estado=!estado">Editor</button>
import { Component } from '@angular/core';
@Component({
 selector: 'my-app',
 templateUrl: './app.component.html',
 styleUrls: [ './app.component.css' ]
})

 export class AppComponent  {
  public estado : boolean = false;
}