【问题标题】:ngx-chips: adding to other input field onRemove doesn't workngx-chips:添加到其他输入字段 onRemove 不起作用
【发布时间】:2018-08-02 14:13:59
【问题描述】:

我正在使用带有两个输入字段的https://github.com/Gbuomprisco/ngx-chips。如果标签从第一个输入(“喜欢”)中删除,它将被添加到第二个输入(“不喜欢”)。

如果先在第二个字段中有一些输入,这将不起作用。

TS:

public likes = [];
public dislikes = [];

onLikeRemove(tag) {
  this.dislikes.push(tag);
  console.log(this.dislikes);
}

HTML:

<tag-input [ngModel]="likes" (onRemove)="onLikeRemove($event)">
</tag-input>

<tag-input [ngModel]="dislikes">
</tag-input>

演示: https://stackblitz.com/edit/ngx-chips-example-5ajdec?file=app/shared/tag-input/tag-input.component.html

复制步骤

1) 为“不喜欢”添加标签

2) 为“喜欢”添加标签

3) 从喜欢中删除标签 - 它应该添加到不喜欢中,但这不起作用。

这是库中的错误还是我遇到了更基本的错误?

【问题讨论】:

  • 您必须在点赞列表的 onRemove() 事件中将删除的项目推送到不喜欢列表中,它不会自动执行。
  • 我不正是这样做的吗?虽然忘记发布我的代码,只是提供了演示。更新了我的问题。
  • 我没有在这个 stackblitz 中获得编辑器,看不到代码
  • 抱歉,我是 stackblitz 的新手。我更新了链接,你现在应该可以看到代码了:stackblitz.com/edit/ngx-chips-example-5ajdec?file=app/shared/….

标签: angular ngx-chips


【解决方案1】:

在代码中使用两种方式绑定来反映 UI 上的更改:

<tag-input [(ngModel)]="likes" (onRemove)="onLikeRemove($event)">
</tag-input>

<tag-input [(ngModel)]="dislikes">
</tag-input>

【讨论】:

    猜你喜欢
    • 2020-09-02
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多