Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49266

Dynamically Reference Class Variables from inside a function

$
0
0

@Luzaan wrote:

Hi,

I was basically wondering how to reference the variables previously set in the class from within a function based on some dynamic input.

as an example to help clarify what I mean, here is my code.

First I have an ion-input field in the HTML file:

         <ion-item>
          <ion-label position="floating">Nickname</ion-label>
          <ion-input 
            type="text"
            name="nickName"
            value="{{this.nickName}}"
            (ionBlur)='verifyFieldUpdate($event.target.name, $event.target.value)'
          ></ion-input>

at the top of the .ts file I declare and set the values (with other functions) of a few variables:

title: string;
firstName: string;
lastName: string;
nickName: string;

Here is the function in the .ts file:

verifyFieldUpdate(key, value) {
// I want to do the following
// let testKey = this.key;
// key would be the name of the ion-input field in question.

    let testKey = this.title;

    if (value === testKey) {
      console.log ('SAME');
    } else {
      console.log ('DIFF');
      console.log('HTML Key: ', key);
      console.log('HTML Value: ', value);
    }
  }

but of course

let testKey = this.key;

gives an error, because it does not exist, but how would I reference that variable (title / nickname / etc) from the Key passed into the function?

Is there a way almost like in the html to do?

let testKey = this.{{key}};

Thank you in advance!
Kind Regards

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49266

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>