-2

In my angular 13 app I am using "rxjs": "^7.5.2". I am using switchMap from 'rxjs/operators', I am getting an error saying Property 'switchMap' does not exist on type 'Observable' when I do an ng build. How can I resolve this, any clue Here is the code.

 getUserS() {        
        return this.api.get( 'rest/getusert')
        .pipe(map(this.returnData));
    }
            
     returnData(res: Response){
        return res.json();
    }
    

initGetUsers() {

        this.getUserS() {
        .pipe(switchMap(res => {
            console.log(res);           
        })).subscribe(
               res =>{ 
                   console.log(res);
                   };
               },
               err => {
                   console.error( err );
               },
               () => {
               
                }
            )
        }
user1015388
  • 1,283
  • 4
  • 25
  • 45

1 Answers1

0

There seem to be two problems with your code:

  1. You have a redundant { at this.getUserS() {
  2. Are you sure it's a good idea to use switchMap here? You don't seem to have an "observable of observables" use case and you don't even return the observable. If you just want to do something in addition to subscription, use the tap operator. If you absolutely need to use switchMap, make sure you return an observable inside

For more info about switchMap (and also similar methods like mergeMap) see this article and also that one.

Liel Fridman
  • 1,019
  • 7
  • 11