在Angular 6中使用LinkedIN API“找不到模块:错误:无法解析’rxjs / add / operator / switchMap’”

“Module not found: Error: Can't resolve 'rxjs/add/operator/switchMap'” using LinkedIN API in Angular 6

我试图在Angular应用程序中对LinkedIN API进行简单的API调用。 我的API密钥以及所有这些都是完美的。 由于某些原因,当我的应用程序调用此函数时,出现此错误:"未找到模块:错误:无法解析'rxjs / add / operator / switchMap"

我什至添加了这一行:

1
import 'rxjs/add/operator/switchMap';

到此组件的顶部。

这是我的component.ts总计:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Component } from '@angular/core';
import { LinkedInService } from 'angular-linkedin-sdk';
import 'rxjs/add/operator/switchMap';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent  {
  title = 'LItest';
  public apiKey;
  private basicProfileFields = ['id', 'first-name', 'last-name', 'maiden-name', 'formatted-name', 'phonetic-first-name', 'phonetic-last-name', 'formatted-phonetic-name', 'headline', 'location', 'industry', 'picture-url', 'positions'];
  public lastResponse;


  public constructor(private _linkedInService: LinkedInService) {
  }

  public rawApiCall(){
    const url = '/people/~?format=json';
    this._linkedInService.raw(url)
      .asObservable()
        .subscribe({
          next: (data) => {
            console.log(data);
          },
          error: (err) => {
            console.log(err);
          },
          complete: () => {
            console.log('RAW API call completed');
          }
        });
  }
}


尝试安装

npm install --save rxjs-compat