javascript - How to toggle items from one array in another -


i have json like:

"data":     [{         "max": 10,         "class": "selected",         "type": "numbers"     }] 

i want use loop, start 1 , 10 (my max value) , display numbers inside span like:

<span>1</span><span>2</span>...<span>10</span> 

than if click on span element want element added in new empty array. lets have other empty array:

newarray: array<number> = [] 

will become:

newarray = [1] 

additionally want toggle class when click on span element, taken json.class property.

_hi nikola,

basically use ngfor loop through data array , display values. can bind each items (click) handler function class , inside function can implement toggle logic pure javascript functions checking if item inside newarray indexof if not use push add it, otherwise remove newarray splice

<span *ngfor="let item of data" (click)="toggle(item)">{{item.max}}</span>  

if want toggle class selector can this:

<span [class]="item.currentclass" *ngfor="let item of data" (click)="toggle(item)">{{item.max}}</span>  

and inside toggle() method can assign item.currentclass = item.class or item.currentclass='' depending on toggle state.

see this demo , let me know if more clear how it.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -