如何将角度中的两个值中的第一个值发送到节点?

时间:2018-12-29 05:24:55

标签: javascript angular

单击按钮,我得到两个folderid,现在我只想发送服务中的第一个Folderid,怎么可能?

请参见下面的屏幕快照,单击folder-1(文件夹ID为1230),它会打开并使用folderid在folder-1内显示四个文件夹。现在,我单击folder-1-1(folderid为1231),但是它需要两个folderids 1231和1230都在控制台中看到仅获得一个folderid的任何可能性,或者是否仅将第一个folderid发送到服务器端?

enter image description here

HTML

<div *ngFor="let folder of folderObjs" (click)="getFolderName(folder.folderid)">{{folder.folderName}}
  <div *ngFor="let pattern of patternObj" (click)="getFolderName(pattern.folderid)">
    {{pattern.folderName}}
  </div>
</div>

TS

getFolderName(folderid){
   console.log(folderid); // 1231
                             1230
   this.userService.getFolderName({'folderid': folderid}).subscribe(
    (data) => {
      console.log(data.payload); 
    }
  )
}

2 个答案:

答案 0 :(得分:3)

问题在于内部点击会向父级冒泡-这应该可以解决问题:

<div *ngFor="let folder of folderObjs" (click)="getFolderName($event, folder.folderid)">{{folder.folderName}}
  <div *ngFor="let pattern of patternObj" (click)="getFolderName($event, pattern.folderid)">
    {{pattern.folderName}}
  </div>
</div>

getFolderName(e, folderid){
   e.cancelBubble = true;
   this.userService.getFolderName({'folderid': folderid}).subscribe(
    (data) => {
      console.log(data.payload); 
    }
  )
}

答案 1 :(得分:2)

不确定我是否在跟踪错误,但是...

我认为当您单击folder-1-1时,它也会同时单击folder-1,因为它是父级。

尝试一下:

<div *ngFor="let folder of folderObjs">
  <span (click)="getFolderName(folder.folderid)">{{folder.folderName}}</span>
  <div *ngFor="let pattern of patternObj" (click)="getFolderName(pattern.folderid)">
    {{pattern.folderName}}
  </div>
</div>