Using ng2-currency-mask input mask in an Ionic 3 app can be a bit challenging, especially when dealing with the input focus issue. If you're having trouble understanding how to implement the fix provided by the ng2-currency-mask library, don't worry, I'm here to help!
Child Component
.html
<div>
<input currencyMask type="tel" [(ngModel)]="value" [id]="'yourInputId' + index"
(focus)="scrollTo(index)" />
</div>
.ts
import { Content } from 'ionic-angular';
export class...
@ViewChild(Content) content: Content;
scrollTo(index) {
let yOffset = document.getElementById('yourInputId' + index).offsetTop;
this.content.scrollTo(0, yOffset + 20);
}
Confused about the [id]="'yourInputId' + index"
part? Let me explain how you can set that up in your Ionic app.
To learn more about it, check out this link.
Update:
I see that you've attempted to implement the solution, but encountered a compile-time error due to the use of index
. Don't worry if you don't have any loops - we can figure this out together.
<input currencyMask type="tel" [ngModel]="data?.budget"
[options]="{ prefix: '', thousands: ',', decimal: '' }"
formControlName="budget"
(ngModelChange)="data.budget=$event;calculateContingency()"
[id]="'yourInputId' + index" (focus)="scrollTo(index)"/>
My component structure:
parent.html
<ion-content class="project">
<ion-grid>
<ion-row class="details">
<project [data]="data"></project>// above code is in this child componet
</ion-row>
</ion-grid>
</ion-content>