Skip to content

Bug: cdkObserveContent callback does not trigger change detection correctly #11280

Open
@jianliao

Description

@jianliao

Bug, feature request, or proposal:

Update a variable of component in the callback function of cdkObserveContent directive. The component template will not be updated. No debounce setting, it should not runoutsideAngular?

For example,
Template snippet:

<h2 (cdkObserveContent)="_onContentChange()">Here are some links to help you start: {{variable}} </h2>
<ul [class.has-bgColor]="_hasBgColor">
......
</ul>
<button (click)="_onToggleButtonClick2()">Touch Label</button>

Component snippet:

_hasBgColor = true;
variable = 1;

_onContentChange() {
  this._hasBgColor = !this._hasBgColor;
  this._changeDetectorRef.markForCheck();
}

_onToggleButtonClick2() {
  this.variable += 1;
}

What is the expected behavior?

CD should be triggered and template should be updated.

What is the current behavior?

What are the steps to reproduce?

I try it with stackblitz, but it has issue.

What is the use-case or motivation for changing an existing behavior?

I want to know what can or can't do in cdkObserveContent callback.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Is there anything else we should know?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/observersneeds: discussionFurther discussion with the team is needed before proceeding

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions