如何延迟角度视图更新

我必须延迟角度视图的渲染,以便可以将当前视图的答案与新获取的值进行比较。经过1秒钟的比较,我将根据获取的视图更新视图。

JSON结构

      {
        id: 1,
        que: "Question A",
        options: ["Option A of 1", "Option B of 1", "Option C of 1", "Option D of 1"],
        ans: null // answer will be in next question
      },
      {
        id: 2,
        que: "Question B",
        options: ["Option A of 2", "Option B of 2", "Option C of 2", "Option D of 2"],
        ans: "Option A of 1" //this is answer of que id 1
      },
      ...

去做:

1. Fetch next question on click of any options (Already done)
2. Check if clicked option is correct by comparing it answer of fetched question.
3. If correct add class "correct" to the clicked div having class "option"
4. If wrong add class "incorrect" to the clicked div having class "option"
5. After 1 seconds fill new question and it's option that you have fetched in step 1

https://stackblitz.com/edit/angular-ivy-soqwnx?file=src%2Fapp%2Fapp.component.ts

评论