- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个一般的 Angular 问题:
为什么 Angular async
管道使用cdr.markForCheck()
而不是 cdr.detectChanges()
?
我看到这两种“风格”有两个主要区别:
markForCheck()
标记要检查到根组件的路径 - 更新什么 markForCheck()
让变更检测发生在当前或下一个周期 - 计时 async
管道中)?为什么不只是当前组件? ( detectChanges()
) - 这与 有关更新什么 markForCheck()
中使用 ngZone)?为什么不立即检测变化? ( detectChanges()
) 这与 有关计时async
管道使用 detectChanges()
反而? private _updateLatestValue(async: any, value: Object): void {
if (async === this._obj) {
this._latestValue = value;
this._ref.markForCheck();
}
}
编辑:
async
观点看法。
最佳答案
有关正确的文档检查 ChangeDetectorRef
检测变化
Checks this view and its children
When a view uses the OnPush (checkOnce) change detection strategy, explicitly marks the view as changed so that it can be checked again.
onPush
的情况。 (例如,如果
@Input()
已更改)。
why do we need to check whole path to the root (in async pipe)? Why not just current component? (detectChanges()) - this relates to what to update
why just mark only (for current/next cycle - in markForCheck() using ngZone)? Why not detect changes immedially? (detectChanges()) this relates to timing
what if there is no ngZone async trigger / no async operation? Then the view update won't happen?
what would happen if we changed async pipe to use detectChanges() instead?
关于angular - 为什么 Angular 异步管道使用 cdr.markForCheck() 而不是 cdr.detectChanges()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64423407/
我将从以下概念开始这个问题:我在 StackOverflow 上看到了一个类似的问题,但该问题只回答了差异。 我想问的是我应该根据情况使用什么以及一种或另一种方法可能有什么缺点。 我知道 detect
说, - 有一个父组件 A 和一个子组件 B。 在组件B上设置OnPush。 有一刻,B 的一个不是输入绑定(bind)属性的属性发生变化,我想检测该变化并相应地更新 View 。 根据我的理解,应该
很明显,我们主要需要使用 markForCheck() 和 OnPush 策略来标记组件进行 CD 检查,但是 我想弄清楚为什么只检查一个分支: 为什么可以为整个应用或仅特定组件运行 CD,不是吗
一般 我有一个问题。如果不调用 changeDetectorRef.markForCheck 方法,我的组件不会重新呈现。 我有一个自动完成功能。当输入更改时,我发送一些异步请求(只是简单的 Http
ChangeDetectorRef.markForCheck()有什么区别和 ChangeDetectorRef.detectChanges() ? 我只有found information on S
我不太明白为什么我需要在下面的代码中添加 markForCheck() 以使更改可见。为什么我的 @Input() 没有触发更改检测? 我正在将我的项目重构为 OnPush。这两个组件都启用了 OnP
我正在阅读 this文章中包含有关何时使用的部分 markForChange() . 在他的例子中,他有以下组件: @Component({ selector: 'cart-badge', t
到处都说 markForCheck 只是将当前组件 View 和所有父组件(直到根组件)标记为脏。所以下次 DetectChanges 执行时它会更新 View 。 从这一点上我有两个问题。两者都在组
无法获得 Angular Material 步进器。步进器显示按照要求,当单击标题时正在移动,但出现错误并显示: Cannot read property markForCheck of undefi
我的应用程序组件正在订阅商店选择。我将 ChangeDetectionStrategy 设置为 OnPush。我一直在阅读有关其工作原理的信息;需要更新对象引用以触发更改。但是,当您使用异步管道时,A
我正在阅读有关 Zone.JS 和 Angular 更改检测过程的信息,在代码源中,Zone.JS 通知 Angular 有关更改并通过将检查传播到所有组件从上到下在第一个组件中运行验证,但在我的测试
我有一个一般的 Angular 问题: 为什么 Angular async管道使用cdr.markForCheck()而不是 cdr.detectChanges() ? 我看到这两种“风格”有两个主要
我想知道使用一个相对于另一个的优势或劣势是什么: constructor(private app:ApplicationRef, private ref:ChangeDetectorRef) {
我是一名优秀的程序员,十分优秀!