0

I'm having an issue with an ion-input, which drops this error below when holding down the delete key.

"Error: Invalid argument '' for pipe 't'
    at new Error (native)
    at Error.v (file:///android_asset/www/build/polyfills.js:3:4864)
    at e [as constructor] (file:///android_asset/www/build/main.js:94:11171)
    at new e (file:///android_asset/www/build/main.js:14:10469)
    at n (file:///android_asset/www/build/main.js:9:10302)
    at t.transform (file:///android_asset/www/build/main.js:9:11000)
    at file:///android_asset/www/build/main.js:1:17764
    at e.detectChangesInternal (file:///android_asset/www/build/main.js:125:10032)
    at e.t.detectChanges (file:///android_asset/www/build/main.js:4:8847)
    at e.t.internalDetectChanges (file:///android_asset/www/build/main.js:4:8640)
    at e.detectChangesInternal (file:///android_asset/www/build/main.js:120:27362)
    at e.t.detectChanges (file:///android_asset/www/build/main.js:4:8847)
    at t.detectChangesInNestedViews (file:///android_asset/www/build/main.js:4:28534)
    at e.detectChangesInternal (file:///android_asset/www/build/main.js:80:24234)
    at e.t.detectChanges (file:///android_asset/www/build/main.js:4:8847)", source: file:///android_asset/www/build/main.js (29)

This one below is my ion-input:

<ion-input color="primary_light" [(ngModel)]="montco_ui" type="number 
(keyup)="formataNumero()"></ion-input>

Also, I'm using this algorithm to handle 2 decimal places, which is working fine, since I guess the issue is related to the type number property on the ion-input.

formataNumero(separador: string = '.', decimais: number = 2) {
    console.log('formataNumero called');
    let a: any = this.montco_ui.split('');
    let ns: string = '';
    a.forEach((c: any) => { if (!isNaN(c)) ns = ns + c; });
    ns = parseInt(ns).toString();
    if (ns.length < (decimais + 1)) { 
        ns = ('0'.repeat(decimais + 1) + ns); 
        ns = ns.slice((decimais + 1) * -1); 
    }
    let ans = ns.split('');
    let r = '';
    for (let i = 0; i < ans.length; i++) 
        if (i == ans.length - decimais) {
          r = r + separador + ans[i]; else r = r + ans[i];
        }
         
    this.montco_ui = r;

}

Finally, this is the variable that keeps the value:

P.S.: I'm using Ionic 2 for my project.

public montco_ui: string = "0.00";
5
  • Did u check if formstaNumero function is being called on deleting? Commented Aug 4, 2022 at 10:19
  • Yes, it is – even when the UI gets unresponsive, If I keep pressing the "delete" button, the function is called and the value of montco_ui is NaN – I guess the crash is related to the type="number" property, which obviously doesn’t accept an empty '' value. Commented Aug 4, 2022 at 14:13
  • the point is that inside this function u are setting this.montco_ui = r; and in html part you are also binding [(ngModel)]="montco_ui" so since they are being done at the same time, then the conflect is occuring Commented Aug 4, 2022 at 15:23
  • and considering the logic of the function, is this just to add 2 decimals after the dot?if so, then u can just use this const numb: string = '15'; const decimal_numb = parseFloat(numb).toFixed(2); and it should output 15.00 so it will always keep 2 numbers after the dot and the string could also be float, that in case if u didn't know about it.. Commented Aug 4, 2022 at 15:29
  • Got it, I'm gonna try that – I know about the toFixed(2), I've previously used it – would it work as I type a digit into the input? – Because that algorithm processes the digits and they are entered into the input and adds the decimal places. Commented Aug 4, 2022 at 16:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.