Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70433

Http.get not resolved when route param changes

$
0
0

@alkahtani wrote:

I have an issue to figure out why http.get working only in first call but nothing happed when i use back button and route again to the same page “only first rout resolve date and if use back button and route again with new route parameter http.get not get any data”.

Service Code

public getListingDataSource(slug: string): Observable<FoodListingModel> {
     console.log('service : get param  ' , slug ); 
  // i have an issue here , this return wont executed when route param changed , it resolved in the first time only.
     return this.http.get<FoodListingModel>('./assets/sample-data/food-listing/listing.json')
     .pipe(map(res => {
       const items = res.items.filter(item => item.slug === slug);
       res.items = items;
       return res;
     })) ;
    }

Resolver code

resolve(route: ActivatedRouteSnapshot ) {
    const  itemSulg = route.paramMap.get('categoryId');
    const  dataSource: Observable<FoodListingModel> = this.foodListingService.getListingDataSource(itemSulg);
    const  dataStore:  DataStore<FoodListingModel> = this.foodListingService.getListingStore(dataSource);
    return dataStore;
  }

.page.ts code

this.route.data.subscribe((resolvedRouteData) => {
      const listingDataStore = resolvedRouteData['data'];
      listingDataStore.state.subscribe(
        (state) => {
          this.listing = state;
        },
        (error) => {
          console.log(error);
        }
      );
    },
    (error) => {
      console.log(error);
    });

module.ts

const routes: Routes = [
  {
    path: '',
    component: FoodListingPage,
    resolve: {
      data: FoodListingResolver,
    },
    runGuardsAndResolvers: 'always',
  }
];

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70433

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>