Is there a way to access a variable declared inside a component in an Angular service file? I tried searching online but couldn't find a solution that fits my needs.
mylib.component.ts
import { Component, Input } from '@angular/core';
@Component({
selector: 'srr-mylib',
template: `
<h1> {{counter}} </h1>
<button class="btn btn-primary" (click)=counterIncrease()>Increase</button>
`,
styles: [
]
})
export class MylibComponent implements OnInit {
counter: number = 0 // the variable I want to access in the service file
constructor( ) {}
ngOnInit(){
}
counterIncrese() {
this.counter = this.counter + 1;
}
}
mylib.service.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class MylibService {
constructor() { }
getCounter(){
//Function that needs to use the 'counter' variable
}
}