Skip to main content

Posts

Showing posts with the label state

Using NGXS actions instead of repeating API calls

Photo by Branko Stancevic on Unsplash    When you need to send an API call , be it GET, POST or any other http request call, you can incorporate the use of State Management implementation, such as NGXS. NGXS is a state management pattern + library for Angular . It acts as a single  source of truth for your application's state, providing simple rules for  predictable  state mutations - NGXS documentation.   Here is the example of sending a GET request through a service call.   ngOnInit(): void {     this.spinnerLoading = true;     this.dataSource$ = this.postListService.getPosts();     this.getPostsData();     this.spinnerLoading = false;    }   getPostsData() {     this.dataSource$.subscribe(        ( res )...