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
})
((変数へのオブジェクトの
割り当てアレイに望んでいたものの.subscribe()が、それはうまくいきません
heroService
getHeroes() { return Observable.of(HEROES); }
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