replaceWith并删除原始div

问题描述 投票:0回答:1

我正在Angular中构建测验应用程序,并已使用replaceWith将说明移至问题框中,但是现在我需要从正确答案的下方隐藏原始说明,不确定如何执行此操作。仅当选择了正确答案时,replaceWith才应该发生。我还需要解释才能在测验中找到每个问题的正确答案,并且类似地从正确答案下方删除原始解释。

<div [hidden]="!isCorrect(option.optionValue)">
  <div id="explanation">
    Option {{ question.answer }} was correct because {{ question.explanation }}.
  </div>
</div>

ngAfterViewInit() {
  this.itemFrom = document.getElementById('explanation');
  this.itemTo = document.getElementById('question');
}

radioChange(answer) {
  this.question.selectedOption = answer;
  this.answer.emit(answer);
  this.moveExplanation(this.itemFrom, this.itemTo);

  if (this.option === this.question.answer && this.question.selectedOption === this.question.answer) {
    this.count++;
    this.score++;
  }
}

moveExplanation(from, to) {
  to.replaceWith(from);
}
javascript angular dom viewchild
1个回答
0
投票
用#myElement标签装饰说明div以删除说明。
© www.soinside.com 2019 - 2024. All rights reserved.