Is there any way to use access the variable MyVariable
from the StartPage
class without using this.
? The reason I am asking is that I need to reference this in a function, and this
does not work there. I know from here that I could use => {...
but that won't always work for me. How can I do this?
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-start',
templateUrl: './start.page.html',
styleUrls: ['./start.page.scss'],
})
export class StartPage implements OnInit {
constructor() {}
MyVariable = "Value";
ngOnInit() {
console.log(MyVariable);
//anyway to use MyVariable without `this.` prefix?
}
}