Considering a component structured as follows:
import { Component, OnInit, ViewChild } from '@angular/core';
@Component({
selector: '...',
templateUrl: './...html',
styleUrls: ['./...scss']
})
export class TestClass implements OnInit {
testVariable : string = 'Test';
constructor() { }
ngOnInit() {}
printTest(): void{
console.log(this.testVariable);
}
}
If I attempt to invoke the printTest method from a different component, the output appears as undefined. What might be causing this behavior and how can it be resolved?