Lately, I have been using the following method to set the value of a subscription to a property in my classes:
export class ExampleComponent implements OnInit {
exampleId: string;
constructor(public route: ActivatedRoute) {
this.route.params.subscribe((params: Params) => this.exampleId = params.id);
}
ngOnInit() {
// Do something with exampleId here...
}
}
As I strive to shift towards immutability over mutation, I am seeking a way to assign the subscription's return value directly to the exampleId
property without relying on the constructor. How can I achieve this in the most effective manner?