'AngularFireObject<unknown>'.ts 类型上不存在属性“take”

时间:2021-02-11 21:34:41

标签: angular typescript cordova ionic-framework

'AngularFireObject'.ts 类型上不存在属性 'take'

我正在处理的 Ionic 应用程序的 4 个位置的代码中出现此错误,我无法找到解决它的方法,即使在网上查找并自己尝试之后也是如此。似乎没有关于 take() 方法关于它做了什么或做了什么的信息。我就是想不通!

我正在使用 npm Ionic 的 AuthService 模块。这段代码没有改变,但我已经升级了项目中的一些组件。这是产生上述错误的代码。

this.authService.go().take(1).subscribe(snapshot => {
  if (snapshot.$value > 0) {
    this.navCtrl.push(HomePage);
    return;
  }
});

这是我的 package.json 文件

{
  "name": "",
  "version": "0.0.25",
  "author": "",
  "homepage": "",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/compiler": "11.1.1",
    "@angular/compiler-cli": "11.1.1",
    "@angular/fire": "^6.1.4",
    "@angular/forms": "11.1.1",
    "@angular/http": "5.0.1",
    "@angular/platform-browser": "11.1.1",
    "@angular/platform-browser-dynamic": "11.1.1",
    "@ionic-native/background-geolocation": "^5.31.1",
    "@ionic-native/background-mode": "^5.31.1",
    "@ionic-native/camera": "^5.31.1",
    "@ionic-native/core": "5.31.1",
    "@ionic-native/date-picker": "^5.31.1",
    "@ionic-native/device": "^5.31.1",
    "@ionic-native/file": "^5.31.1",
    "@ionic-native/file-path": "^5.31.1",
    "@ionic-native/file-transfer": "^5.31.1",
    "@ionic-native/geolocation": "^5.31.1",
    "@ionic-native/google-maps": "^5.5.0",
    "@ionic-native/http": "^5.31.1",
    "@ionic-native/in-app-browser": "^5.31.1",
    "@ionic-native/network": "^5.31.1",
    "@ionic-native/onesignal": "^5.31.1",
    "@ionic-native/pedometer": "^5.31.1",
    "@ionic-native/photo-library": "^5.31.1",
    "@ionic-native/safari-view-controller": "^5.18.0",
    "@ionic-native/splash-screen": "5.31.1",
    "@ionic-native/status-bar": "5.31.1",
    "@ionic-native/transfer": "^3.14.0",
    "@ionic/pro": "^2.0.4",
    "@ionic/storage": "^2.3.0",
    "@types/cordova": "0.0.34",
    "@types/google-maps": "^3.2.2",
    "angular-authentication-service": "^1.1.8",
    "angular-gauge": "^4.0.0",
    "angular-progress-bar": "^1.0.11",
    "angularfire2": "^5.4.2",
    "angularfire2-offline": "^4.3.1",
    "brmasker-ionic-3": "^1.6.3",
    "cordova-android": "^9.0.0",
    "cordova-android-support-gradle-release": "^3.0.1",
    "cordova-background-geolocation-lt": "^3.9.4",
    "cordova-ios": "^6.1.1",
    "cordova-plugin-add-swift-support": "^2.0.2",
    "cordova-plugin-advanced-http": "^3.1.0",
    "cordova-plugin-app-version": "^0.1.12",
    "cordova-plugin-background-mode": "0.7.3",
    "cordova-plugin-camera": "^5.0.1",
    "cordova-plugin-cocoalumberjack": "0.0.4",
    "cordova-plugin-datepicker": "^0.9.3",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-filepath": "^1.5.6",
    "cordova-plugin-googlemaps": "^2.7.1",
    "cordova-plugin-googlemaps-sdk": "git+https://github.com/mapsplugin/cordova-plugin-googlemaps-sdk.git#3.8.0",
    "cordova-plugin-inappbrowser": "^4.1.0",
    "cordova-plugin-ionic": "^5.0.0",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-ios-camera-permissions": "^1.2.0",
    "cordova-plugin-network-information": "^2.0.2",
    "cordova-plugin-photo-library": "^2.3.1",
    "cordova-plugin-splashscreen": "6.0.0",
    "cordova-plugin-statusbar": "^2.4.3",
    "cordova-plugin-transport-security": "~0.1.2",
    "cordova-plugin-whitelist": "1.3.4",
    "cordova-sqlite-storage": "^5.1.0",
    "fcm": "^1.0.3",
    "firebase": "^8.2.*",
    "ion-multi-picker": "^2.1.3",
    "ionic": "^5.4.4",
    "ionic-angular": "^3.9.10",
    "ionicons": "5.4.0",
    "moment": "^2.29.1",
    "node-sass": "^5.0.0",
    "onesignal-cordova-plugin": "^2.11.2",
    "rxjs": "^5.5.11",
    "rxjs-compat": "^6.6.3",
    "simple-crypto-js": "^3.0.0",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.11.3"
  },
  "devDependencies": {
    "@angular/common": "^11.1.2",
    "@angular/core": "^6.0.0-rc.0",
    "@ionic/angular": "^5.5.4",
    "@ionic/app-scripts": "3.2.4",
    "com-sarriaroman-photoviewer": "^1.2.5",
    "cordova-plugin-background-fetch": "^6.1.1",
    "cordova-plugin-safariviewcontroller": "^1.6.0",
    "typescript": "4.1.3"
  },
  "config": {
    "ionic_bundler": "webpack",
    "ionic_source_map": "source-map",
    "ionic_source_map_type": "#inline-source-map",
    "ionic_copy": "./config/webpack.config.js"
  },
  "description": "MedalMad Running App",
  "cordova": {
    "plugins": {
      "cordova-plugin-camera": {},
      "cordova-plugin-device": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-ios-camera-permissions": {
        "CAMERA_USAGE_DESCRIPTION": "This app needs camera access",
        "MICROPHONE_USAGE_DESCRIPTION": "This app needs microphone access",
        "PHOTOLIBRARY_ADD_USAGE_DESCRIPTION": "This app needs write-access to photo library",
        "PHOTOLIBRARY_USAGE_DESCRIPTION": "This app needs read/write-access photo library access"
      },
      "cordova-plugin-statusbar": {},
      "cordova-plugin-app-version": {},
      "cordova-plugin-background-mode": {},
      "cordova-plugin-advanced-http": {
        "OKHTTP_VERSION": "3.10.0"
      },
      "cordova-background-geolocation-lt": {
        "OKHTTP_VERSION": "3.10.0",
        "GOOGLE_API_VERSION": "16.+",
        "APPCOMPAT_VERSION": "28.+",
        "EVENTBUS_VERSION": "3.0.0",
        "BACKGROUND_MODE_LOCATION": "<string>location</string>",
        "LICENSE": "4b54a050b2e6c3226c30cc86cc9d43ea35d99218d54492ca6eaea2aebed91aa8",
        "LOCATION_ALWAYS_AND_WHEN_IN_USE_USAGE_DESCRIPTION": "Always use is required for constant background location-tracking",
        "LOCATION_ALWAYS_USAGE_DESCRIPTION": "Background location-tracking is required",
        "LOCATION_WHEN_IN_USE_USAGE_DESCRIPTION": "Background location-tracking is required",
        "MOTION_USAGE_DESCRIPTION": "Using the accelerometer increases battery-efficiency by intelligently toggling location-tracking only when the device is detected to be moving"
      },
      "cordova-plugin-transport-security": {},
      "cordova-plugin-filepath": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-photo-library": {
        "PHOTO_LIBRARY_USAGE_DESCRIPTION": " "
      },
      "onesignal-cordova-plugin": {},
      "com-sarriaroman-photoviewer": {},
      "cordova-plugin-safariviewcontroller": {},
      "cordova-plugin-datepicker": {}
    },
    "platforms": [
      "ios",
      "android"
    ]
  }
}

这是我的 app.module.ts:

import { AngularFireAuth } from "angularfire2/auth";
import { BrowserModule } from "@angular/platform-browser";
import { ErrorHandler, NgModule, Injectable, Injector } from "@angular/core";
import { IonicApp, IonicErrorHandler, IonicModule } from "ionic-angular";
import { AngularFireModule } from "angularfire2";
import { AngularFireOfflineModule } from "angularfire2-offline";
import { AngularFireDatabaseModule } from "angularfire2/database";
import { MyApp } from "./app.component";
import { AuthService } from "../services/auth-services";
import { HomePage } from "../pages/home/home";
import { ListPage } from "../pages/list/list";
import { SignupPage } from "../pages/signup/signup";
import { RaceResultsPage } from "../pages/race-results/race-results";
import { LoginPage } from "../pages/login/login";
import { BrMaskerModule } from "brmasker-ionic-3";
import { globalService } from "../services/globals";
import { ChallengesPage } from "../pages/challenges/challenges";
import { TrackerPage } from "../pages/tracker/tracker";
import { TrackerWeightPage } from '../pages/tracker-weight/tracker-weight';
import { TrackerUploadOnlyPage } from '../pages/tracker-upload-only/tracker-upload-only';
import { StatsPage } from "../pages/stats/stats";
import { StatusBar } from "@ionic-native/status-bar/ngx";
import { SplashScreen } from "@ionic-native/splash-screen/ngx";
import { Geolocation } from "@ionic-native/geolocation/ngx";
import { SafariViewController } from "@ionic-native/safari-view-controller/ngx";
import { IonicStorageModule } from "@ionic/storage";
import { InAppBrowser } from "@ionic-native/in-app-browser/ngx";
import { HttpModule } from "@angular/http";
import { ProgressBarModule } from "angular-progress-bar";
import { GaugeModule } from "angular-gauge";
import { BackgroundGeolocation } from "@ionic-native/background-geolocation/ngx";
import { CommunityPage } from "../pages/community/community";
import { OneSignal } from "@ionic-native/onesignal/ngx";
import { Camera, CameraOptions } from "@ionic-native/camera/ngx";
import { DatePicker } from '@ionic-native/date-picker/ngx';
import { PhotoLibrary } from "@ionic-native/photo-library/ngx";
import { NotificationPage } from "../pages/notification/notification";
import { BackgroundMode } from "@ionic-native/background-mode/ngx";
import { Device } from "@ionic-native/device/ngx";
import { LeaderBoardPage } from '../pages/leader-board/leader-board';
import { LeaderBoardTeamsPage } from '../pages/leader-board-teams/leader-board-teams'
import { HTTP } from '@ionic-native/http/ngx';
import { Network } from '@ionic-native/network/ngx';
import { ChallengeDownloadsPage } from '../pages/challenge-downloads/challenge-downloads';
import { OrderHistoryPage } from '../pages/order-history/order-history';
import { take } from 'rxjs/operators/take';

// Pro.init('26fccb2a', {
//   appVersion: '0.82'
// })

@Injectable()
export class MyErrorHandler implements ErrorHandler {
  ionicErrorHandler: IonicErrorHandler;

  constructor(injector: Injector) {
    try {
      this.ionicErrorHandler = injector.get(IonicErrorHandler);
    } catch (e) {
      // Unable to get the IonicErrorHandler provider, ensure
      // IonicErrorHandler has been added to the providers list below
    }
  }


  handleError(err: any): void {
    //Pro.monitoring.handleNewError(err);
    // Remove this if you want to disable Ionic's auto exception handling
    // in development mode.
    this.ionicErrorHandler && this.ionicErrorHandler.handleError(err);
  }
}

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    ListPage,
    SignupPage,
    LoginPage,
    ChallengesPage,
    CommunityPage,
    ChallengeDownloadsPage,
    OrderHistoryPage,
    TrackerPage,
    TrackerUploadOnlyPage,
    TrackerWeightPage,
    StatsPage,
    RaceResultsPage,
    LeaderBoardPage,
    LeaderBoardTeamsPage,
    NotificationPage
  ],
  imports: [
    BrowserModule,
    HttpModule,
    BrMaskerModule,
    ProgressBarModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot(),
    GaugeModule.forRoot(),
    AngularFireModule.initializeApp(firebaseConfig),
    AngularFireDatabaseModule,
    AngularFireOfflineModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    ListPage,
    SignupPage,
    LoginPage,
    ChallengesPage,
    TrackerPage,
    TrackerWeightPage,
    TrackerUploadOnlyPage,
    StatsPage,
    RaceResultsPage,
    LeaderBoardPage,
    LeaderBoardTeamsPage,
    NotificationPage,
    CommunityPage,
    ChallengeDownloadsPage,
    OrderHistoryPage
  ],
  providers: [
    BackgroundGeolocation,
    SafariViewController,
    DatePicker,
    Device,
    HTTP,
    Network,
    OneSignal,
    IonicErrorHandler,
    [{ provide: ErrorHandler, useClass: MyErrorHandler }],
    StatusBar,
    SplashScreen,
    Geolocation,
    BackgroundMode,
    PhotoLibrary,
    Camera,
    InAppBrowser,
    { provide: ErrorHandler, useClass: IonicErrorHandler },
    globalService,
    AuthService,
    AngularFireAuth
  ]
})
export class AppModule { }

1 个答案:

答案 0 :(得分:0)

您需要将 take 运算符移动到 pipe 中:

this.authService.go()
  .pipe(take(1))
  .subscribe(snapshot => {
    if (snapshot.$value > 0) {
      this.navCtrl.push(HomePage);
      return;
    }
  });