1. what happens when you call this endpoint from curl or postman tool? Localhost:4200/?town=Brighton 2. you might want to also look at this sample project https://stackblitz.com/angular/mxkjlkldpgj
On Monday, February 11, 2019 at 10:04:00 AM UTC-8, John Biddulph wrote: > > Ok so Step 1 > I am now passing data into the query string as a parameter of town and > when I click on a different town, this changes > > Localhost:4200?town=Brighton > Localhost:4200?town=Oxford > Localhost:4200?town=Manchester > > Great! > > STEP 2 > > I’m stuck, I need to be able to pass this into my pub.service.ts file so I > can change the URL of my JSON > > > > On Mon, 11 Feb 2019 at 17:33, Tito <[email protected] <javascript:>> wrote: > >> so 1 step at a time. did your original issue get fixed? :) >> >> >> On Monday, February 11, 2019 at 9:28:22 AM UTC-8, John Biddulph wrote: >>> >>> So I have the towns being passed into my query in my URL bar in my >>> browser but now I need to get this out into my services file but I put in >>> my PubComponent >>> >>> and here I have this code: >>> this.router.queryParams.subscribe((data) => { >>> this.selectedTown = data['town']; >>> }); >>> and I am now getting the following error: >>> >>> AppComponent.html:3 ERROR TypeError: Cannot read property 'subscribe' of >>> undefined >>> at new PubsComponent (pubs.component.ts:22) >>> >>> >>> >>> >>> >>> On Monday, February 11, 2019 at 3:26:59 PM UTC, John Biddulph wrote: >>>> >>>> I am following this tutorial: >>>> https://alligator.io/angular/query-parameters/ >>>> >>>> here is my code: >>>> townClicked($event) { >>>> this.router.navigate(['/pubs'], { queryParams: { town: $event } }); >>>> } >>>> >>>> and so I get the error >>>> >>>> Error: Uncaught (in promise): Error: Cannot match any routes. URL >>>> Segment: 'pubs' >>>> >>>> >>>> and when I am trying to get the town that is clicked, here is my code: >>>> // tslint:disable-next-line:use-life-cycle-interface >>>> ngOnInit() { >>>> this.route.queryParams >>>> .filter(params => params.town) >>>> .subscribe(params => { >>>> console.log(params); // {order: "popular"} >>>> >>>> this.selectedTown = params.town; >>>> console.log(this.selectedTown); // popular >>>> }); >>>> } >>>> >>> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "Angular and AngularJS discussion" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/angular/IKCTEjp6KlM/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://groups.google.com/group/angular. >> For more options, visit https://groups.google.com/d/optout. >> > -- > Sent from Gmail Mobile > -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
