0
저는 Angular.io 가이드 https://angular.io/guide/router#route-parameters-in-the-activatedroute-service을 따르고 있습니다. 그들은 나를 위해 명확하지 않은 | async
을 사용했고 나는 어떤 custimization을 만들기로 결심했다. .subscribe()가 있지만 ((
을 작동하지 않습니다하지만 난 여기
주 내 코드의 일부이다 변수에 객체의 지정 배열에 원하는변수 배열에 변수를 할당합니다. 서브 스크라이브()
ngOnInit() {
this.heroes$ = this.route.paramMap.switchMap((params: ParamMap) => {
this.selectedId = params.get('id');
return this.heroService.getHeroes();
});
this.heroes$.subscribe((heroes: Hero[]) => {
this.heroes == heroes
console.log(heroes) // Shows array of Objects
console.log(this.heroes) // Shows undefined
})
heroService
getHeroes() { return Observable.of(HEROES); }
영웅
import { Hero } from './hero';
export const HEROES: Hero[] = [
{ id: 11, name: 'Mr. Nice' },
{ id: 12, name: 'Narco' },
{ id: 13, name: 'Bombasto' },
{ id: 14, name: 'Celeritas' },
{ id: 15, name: 'Magneta' },
{ id: 16, name: 'RubberMan' },
{ id: 17, name: 'Dynama' },
{ id: 18, name: 'Dr IQ' },
{ id: 19, name: 'Magma' },
{ id: 20, name: 'Tornado' }
];
나는 어리석은 사람이 될 수있다))) 고마워요! – MardONE