@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