For this example, I am exploring two scenarios of a service that exposes an observable named test$. One case utilizes a getter to access the observable, while the other makes it available as a public field.
Do these approaches have any practical distinctions?
I have come across many instances of declarative programming using the field method. Is utilizing a getter not considered declarative in this context?
In the component:
@Component()
export const TestComp {
private test$ = this.testService.test$;
constructor(private testService: TestService){}
}
Case 1: Service with field value:
@Injectable()
export const TestService {
public test$ = of('test');
}
Case 2: Service with property/getter:
@Injectable()
export const TestService {
private _test$ = of('test');
public get test$() {
return this._test$;
}
}