So previously in Angular 1.X i've been used to creating local variables on the html-side.
It usually looks something like this (AngularJS):
<div class="parentContainer" ng-repeat="error in $ctrl.systemErrorMessages>
<div ng-click="showHide=(showHide ? false : true)">
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Click me to toggle all selectors in the same hierarchical-level (scope) as me.
</div>
<div ng-if="showHide"> {{error.message}} </div>
</div>
The code above will create the variable and show the div inside.
However, if I in Angular 1.X put this within a ng-repeat
tag, that variable would be local to its scope. Lets say there are 50 entries in systemErrMessages
, when i now click the toggle-div, all 50 entries are reacting... it used to be so that - only the message whos toggle-div i clicked; reacted...
It seems that Angular2 breaks the scope of ngFor's, and affects ALL elements.
What i'm trying in (Angular 2):
<div *ngFor="let error of systemErrMessages">
<div class="item" [hidden]="showHide">
ErrorMessage: {{error}}
</div>
<div (click)="showHide=(showHide ? false : true)">TOGGLE above</div>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
</div>
To clarify (TL;DR):
HTML-structure (what the ngFor has generated):
<div class="parentContainer">
<div class="item">
<div class="information" [hidden]="showHide">lorem ipsum</div>
<div (click)="showHide=(showHide ? false : true)">TOGGLE</div>
</div>
<div class="item">...</div>
<div class="item">...</div>
<div class="item">...</div>
<div class="item">...</div>
<div class="item">...</div>
<div class="item">...</div>
</div>
When i click TOGGLE in angular2, ALL elements are visible.
In AngularJS only that .item
's .information
is visible.
Is it possible to get the same behaviour as in 1.X ?