Answer the question
In order to leave comments, you need to log in
Angular 6 how to properly pass service data using routing?
There is a shared service that processes and stores certain data:
@Injectable({
providedIn: 'root'
})
export class DataService {
public filteredMovies: any;
this.router.navigate(['/info/' + title + '/id/' + id]);
import { Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
...
constructor(public _moviesService: MoviesService, private router: Router, private actRouter: ActivatedRoute) { }
...
doSearch(id): void {
// Здесь возникает ошибка (filteredMovies == undefined)
this.asset = this._moviesService.filteredMovies[id];
}
ngOnInit() {
this.actRouter.params.subscribe( params => this.doSearch(params['id']));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question