Angular @指令的输出将在父组件中打印,但无法更新父组件中的值 parent.component.html 可拖动指令 问题

Angular @指令的输出将在父组件中打印,但无法更新父组件中的值 parent.component.html 可拖动指令 问题,angular,angular-directive,Angular,Angular Directive,请参阅父.component.ts中的控制台.log?它总是正确地打印期望值。但在父组件(下一行)中指定一个值不会反映在父html中 是否有什么东西阻止我在父组件中指定发出的值?尝试强制更改检测 constructor(private ref: ChangeDetectorRef) { } copyDragging(event) { console.log('copyDragging :', event); // good this.copyBoxDragging = even

请参阅父.component.ts中的
控制台.log
?它总是正确地打印期望值。但在父组件(下一行)中指定一个值不会反映在父html中


是否有什么东西阻止我在父组件中指定发出的值?

尝试强制更改检测

constructor(private ref: ChangeDetectorRef) {
}

copyDragging(event) {
    console.log('copyDragging :', event); // good
    this.copyBoxDragging = event; // not reflected in html

    this.ref.detectChanges();
}

您希望如何在父视图中反映
copyboxdrading
?我们能看到相关的HTML代码吗?肯定需要相关的html@Omar相关html是显示元素的位置。。。我从v1测试版开始就一直在开发angular,谢谢。祝你好运为什么这会有关系。它只是一个
一些文本

我猜您正在使用一些未包含的代码,这些代码在ng zone之外运行拖动功能以提高性能,但您没有意识到这会破坏更改检测。在ng区域之外运行的目的是关闭更改检测,这就是收益的来源。这里的修复方法是将事件发射封装在类似
this.ngZone.run(()=>this.dragging.emit(true))
的东西中,而不是强制指令的使用者手动触发更改检测。。中断更改检测的组件不是很有用,因为它们会导致这样的错误,而不是问题所在。输出事件始终触发更改检测此解决方案有效。。。让我觉得,可能更改检测在按下键或拖动时不起作用。@Omar更改检测在按下键或拖动时效果很好。。。如果您需要在输出事件中强制使用CD,则您的应用程序中还存在其他可能导致问题的错误
copyDragging(event) {
    console.log('copyDragging :', event); // good
    this.copyBoxDragging = event; // not reflected in html
}
@Output() dragging = new EventEmitter();
mousedrag$.subscribe(() => {
    if (!this._dragging) {
        this.dragging.emit(true);
        this._dragging = true;
    }
});
constructor(private ref: ChangeDetectorRef) {
}

copyDragging(event) {
    console.log('copyDragging :', event); // good
    this.copyBoxDragging = event; // not reflected in html

    this.ref.detectChanges();
}