Handle open/collapse events of Accordion in Angular

后端 未结 7 1411
猫巷女王i
猫巷女王i 2020-11-29 02:04

If I have this code:


      {{group.content}}

         


        
7条回答
  •  盖世英雄少女心
    2020-11-29 02:42

    I used an associative array to create a relationship between the opened state and the model object.

    The HTML is:

      

    {{topic.title}} Updated: {{topic.updatedDate}}

    Topic Description

    {{topic.description}}

    • Comment by: {{comment.author}}Updated: {{comment.updatedDate}} | {{comment.updatedTime}}

      {{comment.comment}}

    The controller snippet is:

       self.model = {
          closeOthers : false,
          opened   : new Array(),
          topics   : undefined
       };
    

    The 'topics' are populated on an AJAX call. Separating the 'opened' state from the model objects that are updated from the server means the state is preserved across refreshes.

    I also declare the controller with ng-controller="CaseController as controller"

提交回复
热议问题