【问题标题】:select and unselect is not working in angular 7?选择和取消选择在角度 7 中不起作用?
【发布时间】:2020-01-19 09:35:30
【问题描述】:

您好,我正在通过选择一个突出显示该部分的图标来进行过滤,取消选择后它没有突出显示它,但是当我选择它时它工作正常但取消选择它的图标消失了,当我刷新时它仍然被选中页面,请查看此图片以供参考when selected 以及何时i unselect it 以及当我刷新页面时it show like this

这是我的工作代码

HTML 代码 -

<div class="flexcell">
 <a *ngIf="data.showcase==1||helper.checkArticleArray(showcasearticle,data.articleid)"
             href="javascript:void(0);"
            (click)="setShowcase(data.articleid,$event)"><svg
             xmlns="http://www.w3.org/2000/svg" width="18" height="18"
             viewBox="0 0 18 18">
           <g id="Group_35" data-name="Group 35"
           transform="translate(-556 -363)">
           <rectid="Rectangle_37" data-name="Rectangle 37"
           width="18" height="18" rx="2"
           transform="translate(556 363)" fill="#2262a0" />
          <path id="star" />
     </g>
     </svg></a> 

这是我的节点代码

showcase(articleid,articlepara){

return this.http.post<any>(this.SERVERURL + this.AppSettings.showcase, {articleid: articleid, articlepara : articlepara});

}

这是我的 .ts 文件

   `setShowcase(articleid, event) {
    event.currentTarget.style.display = "none";

    this.article.showcase(articleid, this.articlepara)
      .subscribe(
        res => {
          //console.log(res);
          this.showcasearticle.push(res.articleid);
          console.log(this.showcasearticle);

        },
        err => {
          console.log(err);
        }
      )
  } 

`

【问题讨论】:

  • 在不知道 article.showcase 的工作原理的情况下,不确定如何保持价值持久。为函数添加代码块。尿布的原因是因为您将显示设置为无,我猜您应该更新填充颜色,而不是将显示设置为无。
  • 我添加了我的节点代码也请检查一次

标签: javascript node.js angular


【解决方案1】:

您正在设置 event.currentTarget.style.display = "none";这导致它消失。您需要的是替换填充颜色。您可以参考this以了解有关角度Angular: transclusion, set color of SVG element的svg操作的更多信息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-08
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多