How to display local variable in a page


#1

I want to display the variable x in my page using {{ }}

Coding snippet:
ionViewDidLoad() {
this.storage.get(‘savedData’).then((data) => {
this.getData(data);
});

getData(data){
var x=data[0].awb;
}


#2

define this var global and bind

public let x : any // globaly defined

this.x = data[0].awb
{{x}}


#3

This makes no sense, and doesn’t even compile. let declares lexically-scoped variables, and doesn’t belong on object properties.


#4

public x: any;

getData(data){
    // If you declare var x here, it belongs to your function scope
    this.x = data[0].awb;
}

html:

<p>{{x}}</p>

#5

Thank you for reply.