Директива @Output from будет печататься в родительском компоненте, но не может обновить значение в родительском компоненте. - PullRequest
0 голосов
/ 30 апреля 2020

parent.component. html

  <div draggable (dragging)="copyDragging($event)">{{copyBoxDragging}}</div>

parent.component.ts

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

draggable.directive

@Output() dragging = new EventEmitter();
mousedrag$.subscribe(() => {
    if (!this._dragging) {
        this.dragging.emit(true);
        this._dragging = true;
    }
});

Проблема

См. console.log в parent.component.ts ? Всегда правильно печатает ожидаемое значение. но присвоение значения родительскому компоненту (следующая строка) не отражается в родительском html

Есть ли что-то, что мешает мне присвоить значение в родительском компоненте?

1 Ответ

2 голосов
/ 30 апреля 2020

попытаться принудительно обнаружить изменение

constructor(private ref: ChangeDetectorRef) {
}

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

    this.ref.detectChanges();
}
...