Remove or add class in Angular

前端 未结 5 2054
感动是毒
感动是毒 2021-02-14 08:37

I have a list and the plugin (dragula) I used, adds certain CSS class on certain action. I am using Angular 5. I want to find out the presence of certain class (

5条回答
  •  猫巷女王i
    2021-02-14 09:22

    If you want to change all li.myClass, you can do like this:

    Note the #questions in the container div.

    Component.ts

    @ViewChild('questions') questions: any;
    
    questions.nativeElement.querySelectorAll('.myClass').forEach(
      question => {
        question.classList.remove('myClass');
        question.classList.add('newClass');
      }
    )
    

    Component.html

    {{ questions.length == 0 ? ' Drag and drop questions here ' : ' '}}
  • {{question.questionId}} {{question.questionSentence}}
提交回复
热议问题