TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined

12,000

I think that you missed a return in the retryWhen:

.retryWhen(error => {
  return error.delay(3000);
})
Share:
12,000
zpul
Author by

zpul

Nothing special to say.

Updated on July 20, 2022

Comments

  • zpul
    zpul almost 2 years

    I get the following exception when a web service request fails.

    TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
    

    Specifically the HTTP GET returns 400 Bad request.

    Here you can find the involved component:

    @Component({
        selector: 'events-list',
        directives: [EventRow],
        changeDetection: ChangeDetectionStrategy.OnPush,
        providers: [HTTP_PROVIDERS],
        template: `
    <table>
        <tr *ngFor="let event of events | async" [event]="event" >
        </tr>
    </table>
      `
    })
    export class EventsList implements OnInit {
        events: Observable<Event[]>;
    
        constructor(public http: Http) { }
    
        ngOnInit(): void {
            let obs;
            this.events = Observable
                .create((o) => {
                    obs = o;
                    obs.next();
                })
                .flatMap(() => {
                    return this.http.get('event/view');
                })
                .retryWhen(error => {
                    error.delay(3000);
                })
                .map((response: Response) => {
                    setTimeout(() => {
                        obs.next();
                    }, 10000);
                    return (<any>response.json()).map(item => {
                        return item;
                    });
                });
        }
    }
    

    Any suggestion?

    Thanks in advance!