Skip to content

Instantly share code, notes, and snippets.

@anandadake
Created January 4, 2024 08:39
Show Gist options
  • Select an option

  • Save anandadake/69b1069c9ca15f53b7b2ff27adcbc8fc to your computer and use it in GitHub Desktop.

Select an option

Save anandadake/69b1069c9ca15f53b7b2ff27adcbc8fc to your computer and use it in GitHub Desktop.
Angular Memory Leak Solution
import { catchError } from 'rxjs';
import { FormBuilder } from '@angular/forms';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
@Component({
selector: 'app-brush',
templateUrl: './brush.component.html',
styleUrls: ['./brush.component.css']
})
export class BrushComponent implements OnInit, OnDestroy {
private subscriptions$:any = [];
constructor(
private fb: FormBuilder,
private toastr: ToastrService,
private apiService:WorkspaceApiService,
private stateService:WorkspaceStateService,
) { }
ngOnInit(): void {}
ngOnDestroy(): void {
this.subscriptions$.forEach((subscription:any)=>subscription.unsubscribe());
}
onSave(event:any){
this.subscriptions$.push(this.apiService.brush_add_api({})
.pipe(
catchError((e)=>{
this.toastr.error(e.error.msg, "API Error!");return e;
}),
)
.subscribe((resp:any) => {
this.stateService.setProjectInfoState(resp.data.project_info);
this.toastr.success('Your changes have been saved successfully!', "Successful");
}
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment