Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.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

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
使用“贴图”在Angular2中显示和隐藏组件_Angular_Typescript - Fatal编程技术网

使用“贴图”在Angular2中显示和隐藏组件

使用“贴图”在Angular2中显示和隐藏组件,angular,typescript,Angular,Typescript,我有一个角度为2的对象数组。它总是很小,所以我只是用ngFor渲染它。我想在每个项目旁边显示一个编辑图标,当您单击它时,用编辑框替换文本,并保存和取消图标。这是后端,这段代码在显示对话框之前正在设置映射 public open() { this.showEdit = new Map<number, boolean>(); for(let n =0;n < this.authService.families.length;++n) { t

我有一个角度为2的对象数组。它总是很小,所以我只是用ngFor渲染它。我想在每个项目旁边显示一个编辑图标,当您单击它时,用编辑框替换文本,并保存和取消图标。这是后端,这段代码在显示对话框之前正在设置映射

  public open() {
    this.showEdit = new Map<number, boolean>();

    for(let n =0;n < this.authService.families.length;++n)
    {
      this.showEdit[n] = false;
    }

    this.opened = true;
  }
public open(){
this.showEdit=new Map();
for(设n=0;n
然后,这是我的模板:

<div *ngFor="let f of authService.families; let i = index">
  <span *ngIf="!showEdit[index]"> {{f.name}} </span>
  <span *ngIf="showEdit[index]">
    <input type="text" value="{{f.name}}"/>
     <span class="glyphicon glyphicon-save" (click)="onSave(f.id, i)"></span>
  </span>
   <span *ngIf="!showEdit[index]" class="glyphicon glyphicon-edit" (click)="onEdit(f.id, i)"></span>
</div>

{{f.name}
因此,我们显示名称,方法应该在映射中切换值(确实如此),然后ngIf应该切换并显示另一个控件。这是行不通的。单击切换按钮不会执行任何操作

问题似乎出在地图上,因为如果我创建一个独立的布尔值并使用它,它就可以正常工作


谢谢

好的,我通过对一个从映射返回值的方法执行ngIf来实现这一点。我仍然很想知道为什么原始代码不起作用,但是。你有任何错误吗?没有,只是不起作用。我所做的更改是将ngIf调用设为一个方法,该方法从映射返回值。