'This pattern seems wrong in angular. Multiple calls to an api is generating multiple subscriptions
In my Angular 2+ app I have the following:
ngOnInit() {
debugger;
this.activatedRoute.paramMap.subscribe((params) => {
this.rowid = params.get('rowid')
this.apiService.getrow(this.rowid).subscribe((data) => {
this.data = data;
//Validations
if (this.data == null) return;
if (!("oid" in data)) return;
let oid:string =data["oid"]
})
})
}
}
This seems wrong because every time the params change we create a new api service call that create a new subscription.
I rather not use activatedRoute snapshot.
Is there a better pattern for this. Is there a better way to do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
