0

I'm building an hybrid app using Ionic3+AngularJS, and I'm stuck on this:

I have an input like this:

<ion-input name="test" type="number" placeholder="0" text-center></ion-input>

When the user changes the value of this input, I need that the attribute "name" changes its value too, like this:

<ion-input name="test-changed" type="number" placeholder="0" text-center></ion-input>

Is it even possible? Need help!

Bruno Santos
  • 135
  • 1
  • 10

1 Answers1

0

You change your template to:

<ion-input [name]="name" [(ngModel)]="value" (ngModelChange)="onValueChange()" type="number" placeholder="0" text-center></ion-input>

And in the component ts file:

@Component(...)
export class MyComponent {

    public value: string;
    public name: string = 'test';

    onValueChange() {
        this.name = 'test-changed';
    }

}

If you want that the name become test-changed only if there is something written in the input you could change the method onValueChange() to:

this.name = this.value ? 'test-changed' : 'test';
Lucas Basquerotto
  • 7,260
  • 2
  • 47
  • 61
  • Can you do this for disabling/enabling an ion-input element when a button is clicked? – EnigmaTech May 20 '20 at 17:37
  • @DerryckDX You can try to do something like `` where `condition` is changed when the button is clicked. I have not tried it tough, and I recall that there where some issues with the `disabled` attribute in ionic inputs (because it was not propagated to the nested input), but maybe that was fixed (https://github.com/ionic-team/ionic/issues/5280). – Lucas Basquerotto May 21 '20 at 12:24