Hi
So I am passing a value as an argument through a function and when I get my
list of results, it duplicates the service list for some reason?!
Please help!
here is my component:
import { Component, OnInit } from '@angular/core';
import { PubsService } from '../../services/pubs.service';
import { TownsService } from '../../services/towns.service';
import { HttpClient } from '@angular/common/http';
import { pubs } from '../../interface/pub';
import { Subscription } from 'rxjs';
import { Router, ActivatedRoute } from '@angular/router';
import 'rxjs/add/operator/filter';
import { parse } from 'url';
@Component({
selector: 'app-pubs',
templateUrl: './pubs.component.html',
styleUrls: ['./pubs.component.scss']
})
export class PubsComponent implements OnInit {
public pubsList;
public townsList;
public selectedTown: string;
subscription: Subscription;
constructor(private pubService: PubsService,
private townService: TownsService,
private router: ActivatedRoute,
private router1: Router,
private http: HttpClient) {
// this.pubService.getPubs().subscribe(result => this.pubsList = result);
this.townService.getTowns().subscribe(result => this.townsList = result);
}
townClicked($event) {
this.router1.navigate(['/pubs'], $event);
this.pubService.selectedTown = $event;
console.log('selected Town:', this.pubService.selectedTown);
this.router1.navigate(['/pubs'], { queryParams: { town: $event } });
// this.router.queryParams
// .filter(params => params.town)
// .subscribe(params => {
// console.log('params: ', params); //
// this.pubService.selectedTown = params.town;
// console.log(this.pubService.selectedTown); // popular
// });
this.http.get('http://www.mypubspace.com/pubsmobile/gettownpubs.php?rsTown='
+ $event).subscribe(result => this.pubsList = result);
}
ngOnInit() {
}
}
--
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.