Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change detection broken after multi page survey (Angular 16) #6619

Closed
GarethPrattCv opened this issue Jul 28, 2023 · 2 comments · Fixed by #6621
Closed

Change detection broken after multi page survey (Angular 16) #6619

GarethPrattCv opened this issue Jul 28, 2023 · 2 comments · Fixed by #6621
Assignees
Labels
bug user issue An issue or bug reported by users

Comments

@GarethPrattCv
Copy link

GarethPrattCv commented Jul 28, 2023

If I create a two (or more) page survey, change detection is left broken on survey completion. In this example, I show a results page on survey completion. The button on that page will not work unless I manually trigger change detection.

Steps:

  • Create vanilla angular application
  • Add in angular-survey-ui
  • Add a new component, "Results"
  • Update AppComponent and ResultsComponent:

app.component.html

<survey [model]="surveyModel"></survey>
<app-results *ngIf="complete"></app-results>

app.component.ts

import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { SurveyModel } from 'survey-core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
  public constructor(private readonly changeDetectorRef: ChangeDetectorRef) {}

  public complete = false;

  public surveyModel = new SurveyModel({
    pages: [
      {
        elements: [
          {
            type: 'radiogroup',
            title: 'First question',
            choices: ['Choice 1', 'Choice 2'],
          },
        ],
      },
      {
        elements: [
          {
            type: 'radiogroup',
            title: 'Second question',
            choices: ['Choice 1', 'Choice 2'],
          },
        ],
      },
    ],
  });

  public ngOnInit(): void {
    this.surveyModel.onComplete.add(() => {
      this.complete = true;
      this.changeDetectorRef.detectChanges();
    });
  }
}

results.component.html

<p>This button should show some extra text - but change detection doesn't trigger.</p>
<button (click)="showExtraText = true">Show extra text</button>
<p *ngIf="showExtraText">Extra text</p>

results.component.ts

import { Component } from '@angular/core';

@Component({
selector: 'app-results',
templateUrl: './results.component.html',
})
export class ResultsComponent {
public showExtraText = false;
}

  ```
@dk981234 dk981234 self-assigned this Jul 28, 2023
@dk981234 dk981234 added bug user issue An issue or bug reported by users labels Jul 28, 2023
@dk981234
Copy link
Contributor

Hello,

We'll fix the issue to the next minor update.
For now, you can use this workaround: https://stackblitz.com/edit/angular-pykana?file=src%2Fapp.component.ts

Thanks,
Dmitry
SurveyJS Team

@GarethPrattCv
Copy link
Author

GarethPrattCv commented Jul 28, 2023 via email

dk981234 added a commit that referenced this issue Jul 28, 2023
so that survey events fire correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug user issue An issue or bug reported by users
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants