I am wanting to switch the content of two div in angular2/ionic2 this is my code. It does switch the html but I seem to loose all binding to the elements.
<ion-list>
<div #currencyFromHtml>
<ion-row>
<ion-col col-8>
<ion-item>
<ion-input [(ngModel)]="currencyFromAmount" (ionChange)="refreshConversion()"></ion-input>
</ion-item>
</ion-col>
<ion-col col-4>
<ion-item>
<ion-select [(ngModel)]="currencyFrom" (ionChange)="refreshConversion()">
<ion-option *ngFor="let c of coins; let i = index" [selected]="i==0" [value]="c">{{c.title}}</ion-option>
</ion-select>
</ion-item>
</ion-col>
</ion-row>
</div>
<ion-row>
<button ion-button (click)="switchToAndFromCurrency()">Switch</button>
</ion-row>
<div #currencyToHtml>
<ion-row>
<ion-col col-8>
<ion-item>
<ion-input [(ngModel)]="currencyToAmount" (ionChange)="refreshConversion()"></ion-input>
</ion-item>
</ion-col>
<ion-col col-4>
<ion-item>
<ion-select [(ngModel)]="currencyTo" (ionChange)="refreshConversion()">
<ion-option *ngFor="let cur of currency; let i = index" [selected]="i==0" [value]="cur">{{cur.title}}</ion-option>
</ion-select>
</ion-item>
</ion-col>
</ion-row>
</div>
The code that runs is this:
switchToAndFromCurrency()
{
console.log(this.currencyToHtml.nativeElement.innerHTML);
let toHtml = this.currencyToHtml.nativeElement.innerHTML;
let fromHtml = this.currencyFromHtml.nativeElement.innerHTML;
this.currencyToHtml.nativeElement.innerHTML = fromHtml;
this.currencyFromHtml.nativeElement.innerHTML = toHtml;
}
This does the switch but I lose all the values on the page and the select elements dont work anymore.