【问题标题】:Force update *ngFor Angular 2强制更新 *ngFor Angular 2
【发布时间】:2016-06-02 22:27:44
【问题描述】:

对于我的应用,我需要强制更新 *ngFor 组件。

有什么方法可以从我的代码中强制更新它,例如使用 updateList 函数?

我正在使用 firebasepipe 获取 child_added 事件来更新 ngfor。我需要同时删除一个条目并添加一个条目,但它只会更新添加的内容。

<li *ngFor="#quote of firebaseUrl | firebaseevent:'child_added'"> <strong>"{{quote.text}}"</strong> </li>

【问题讨论】:

标签: typescript angular


【解决方案1】:

问题是 firebaseevent 管道不监听 'child_removed' 事件。

您可以将 child_removed 添加到管道的参数中:

<li *ngFor="#quote of firebaseUrl | firebaseevent:'child_added':'child_removed'"> <strong>"{{quote.text}}"</strong> </li>

注意:在与 OP 长时间交谈后,我们确定 angular2base 不能正确支持 'child_removed' 事件。

【讨论】:

  • Lexer Error: Unterminated quote at column 72 in expression [ngFor #quote of firebaseUrl | firebaseevent:'child_added':'child_removed] (" &lt;/div&gt; &lt;ul class="messages-list"&gt; &lt;li [ERROR -&gt;]*ngFor="#quote of firebaseUrl | firebaseevent:'child_added':'child_removed"&gt; &lt;strong&gt;"{{"): MessageList@11:12
  • 您在 child_removed 的末尾缺少一个 ':P
  • 我更新了问题以使用整个代码示例来防止复制错误。
  • 嗯,现在我没有任何错误,但是当一个孩子被移除时它仍然不起作用。
  • 我认为问题出在 github.com/sararob/angular2base/blob/master/src/firebasepipe.ts 本身。它没有任何关于child_removed 的内容
猜你喜欢
  • 2016-10-10
  • 2018-08-29
  • 2017-11-03
  • 2016-06-11
  • 2017-09-20
  • 2021-09-14
  • 1970-01-01
  • 1970-01-01
  • 2018-10-13
相关资源
最近更新 更多