I think you should add track by $index when ng-repeat, and pass $index into toggle(). Declare a myVar array with the same length as the length you need to repeat. Set the values of the array to true and use ng-if="myVar[$index]" to display them at the beginning. When clicking the expand and shrink button, toggle($index) just inverts the value of the corresponding position in the array.
Because you haven’t used ng-repeat yet, it doesn’t work. If you switch to ng-repeat, it will be fine. In addition, you don’t need to write a toggle, just ng-click="myVar=!myVar"
I think you should add track by $index when ng-repeat, and pass $index into toggle(). Declare a myVar array with the same length as the length you need to repeat. Set the values of the array to true and use ng-if="myVar[$index]" to display them at the beginning.
When clicking the expand and shrink button, toggle($index) just inverts the value of the corresponding position in the array.
Because you haven’t used ng-repeat yet, it doesn’t work. If you switch to ng-repeat, it will be fine.
In addition, you don’t need to write a toggle, just ng-click="myVar=!myVar"