angular.js - The same method in angularjs, how to make the trigger only valid for the current element.
为情所困
为情所困 2017-05-15 17:04:52
0
2
607


The three parts in the big picture are read from the background and then bound using ng-repeat. The function to be implemented is to click on the small corner mark on the far right of each part. , the current part can be expanded or collapsed, but due to ng-rep eat, even the method name and ng-show='myVar' are the same, which will cause the entire area to shrink or expand when you click on any corner icon;
This code requires ng- The base code of repeat has not been modified yet,

$scope.myVar=false;
$scope.toggle=function(){
    this.myVar=!this.myVar;
}
为情所困
为情所困

reply all(2)
習慣沉默

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"

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template