【问题标题】:"Module not found: Error: Can't resolve 'rxjs/add/operator/switchMap'" using LinkedIN API in Angular 6“未找到模块:错误:无法解析 'rxjs/add/operator/switchMap'”在 Angular 6 中使用 LinkedIN API
【发布时间】:2019-02-02 13:38:31
【问题描述】:

我正在尝试在我的 Angular 应用程序中对 LinkedIN API 进行简单的 API 调用。我的 API 密钥和所有这些都是完美的。出于某种原因,当我的应用调用此函数时,我收到此错误:“找不到模块:错误:无法解析 'rxjs/add/operator/switchMap”

我什至加了一行:

import 'rxjs/add/operator/switchMap';

到这个组件的顶部。

这是我的 component.ts 总数:

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');
          }
        });
  }
}

【问题讨论】:

  • Angular6 使用 rxjs6.0.0+,为此,您可以通过import { switchMap } from 'rxjs/operators' 导入运算符,请参阅github.com/ReactiveX/rxjs/tree/6.2.2#es6-via-npm
  • 我遇到了另一个错误。这肯定是解决方法,我很欣赏与解决方案一起提供的文档。
  • 下一个错误是“ERROR TypeError: this.isLoadedObservable.switchMap is not a function at FluentApiCall.push../node_modules/angular-linkedin-sdk/src/fluent.api.call.js。 FluentApiCall.asObservable"
  • 这个包是基于rxjs5开发的,不是rxjs6。 Angular6和这个包有冲突。
  • 不推荐,但是如果你等不及了,那就从 PR 存储库 fork,然后使用 npm 从本地安装。

标签: angular api rxjs linkedin angular6


【解决方案1】:

尝试安装

npm install --save rxjs-compat

【讨论】:

    猜你喜欢
    • 2018-11-23
    • 1970-01-01
    • 2018-11-13
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    • 2018-11-06
    相关资源
    最近更新 更多