Search code examples
angulartypescriptnativescript

How to access a variable in a function and display it in the template - Angular 2 Nativescript


Beginner with both NativeScript and Typescript. I am trying to access a variable that gets declared in a function, so I can display it in the view. If thats not possible, then how should I fix it

TypeScript code:

onValueEvent(result) {
    var cardtitle = result.value.title; // variable I am trying to access in view
    console.log(cardtitle); // logs expected value
}
getCardData(cardID: string) {
    firebase.addValueEventListener(this.onValueEvent, "/cards/" + cardID).then(
        function (listenerWrapper) {
            var path = listenerWrapper.path;
            var listeners = listenerWrapper.listeners;
        });
}

Thanks in advance!


Solution

  • Yes because you don´t use a arrow function