使用 属性 绑定时刷新 Angular 表情符号

Refreshing Angular Emojis when using property binding

我是编程新手,如果这个问题很愚蠢,我深表歉意。 我正在使用 Angular Emojis,我使用 属性 绑定显示带有变量的特定表情符号。

模板:

<angular-emojis [name]="emojivar" size="30" (mouseenter)="changeRoutine()" > </angular-emojis>

TypeScript 代码:

  emojivar = 'taco';

  changeRoutine(){
    console.log(this.emojivar);
    this.emojivar = 'tomato';
    console.log(this.emojivar);
  }

变量变了,表情符号没变。 有什么方法可以修复它,让它刷新吗?

老实说,我看不出有任何原因这行不通。您可以尝试强制更改检测:

consturctor(private cdr: ChangeDetectorRef) {}

changeRoutine(){
    console.log(this.emojivar);
    this.emojivar = 'tomato';
    console.log(this.emojivar);
    this.cdr.detectChanges();
}

[编辑] 我查看了您正在使用的库并且...它根本不处理更改:

https://github.com/saqy/angular-packages/blob/master/projects/angular-emojis/src/lib/angular-emojis.component.ts

希望这篇example我猜对你有帮助。