Filechooser не будет активирован в приложении ionic 3 - PullRequest
1 голос
/ 05 октября 2019

Я создал ионное приложение в ionic 3 и firebase, и теперь я хочу использовать filechooser a [application, но когда я вызываю filechooser, я получаю следующую ошибку.

Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
at FileChooser.open (http://localhost:8100/build/vendor.js:139833:129)
at http://localhost:8100/build/main.js:800:31
at new t (http://localhost:8100/build/polyfills.js:3:14699)
at ImghandlerProvider.webpackJsonp.281.ImghandlerProvider.uploadimage 
(http://localhost:8100/build/main.js:799:23)
at ProfilepicPage.webpackJsonp.482.ProfilepicPage.chooseimage (http://localhost:8100/build/2.js:91:25)
at Object.eval [as handleEvent] (ng:///ProfilepicPageModule/ProfilepicPage.ngfactory.js:164:24)
at handleEvent (http://localhost:8100/build/vendor.js:12251:138)
at callWithDebugContext (http://localhost:8100/build/vendor.js:13543:42)
at Object.debugHandleEvent [as handleEvent] (http://localhost:8100/build/vendor.js:13131:12)
at dispatchEvent (http://localhost:8100/build/vendor.js:9151:21)
at c (http://localhost:8100/build/polyfills.js:3:13190)
at c (http://localhost:8100/build/polyfills.js:3:12876)
at http://localhost:8100/build/polyfills.js:3:13722
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9655)
at Object.onInvokeTask (http://localhost:8100/build/vendor.js:4478:37)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9576)
at r.runTask (http://localhost:8100/build/polyfills.js:3:4831)
at o (http://localhost:8100/build/polyfills.js:3:1891)
at HTMLButtonElement.invoke (http://localhost:8100/build/polyfills.js:3:10673)

Я сузил его до следующего метода, где происходит ошибка.

uploadimage() {
var promise = new Promise((resolve, reject) => {
    this.filechooser.open().then((url) => {
      (<any>window).FilePath.resolveNativePath(url, (result) => {
        this.nativepath = result;
        (<any>window).resolveLocalFileSystemURL(this.nativepath, (res) => {
          res.file((resFile) => {
            var reader = new FileReader();
            reader.readAsArrayBuffer(resFile);
            reader.onloadend = (evt: any) => {
              var imgBlob = new Blob([evt.target.result], { type: 'image/jpeg' });
              var imageStore = this.firestore.ref('/profileimages').child(firebase.auth().currentUser.uid);
              imageStore.put(imgBlob).then((res) => {
                this.firestore.ref('/profileimages').child(firebase.auth().currentUser.uid).getDownloadURL().then((url) => {
                  resolve(url);
                }).catch((err) => {
                    reject(err);
                })
              }).catch((err) => {
                reject(err);
              })
            }
          })
        })
      })
  })
})
 return promise;

}

и мой app.module. ts выглядит так

    import { BrowserModule } from '@angular/platform-browser';
    import { ErrorHandler, NgModule} from '@angular/core';
    import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
    import { SplashScreen } from '@ionic-native/splash-screen';
    import { StatusBar } from '@ionic-native/status-bar';

    import { config } from './app.firebaseconfig';

    import { AngularFireAuth } from 'angularfire2/auth';
    import { AngularFireModule } from 'angularfire2';

    import { MyApp } from './app.component';
    import { AuthProvider } from '../providers/auth/auth';
    import { UserProvider } from '../providers/user/user';
    import { ImghandlerProvider } from '../providers/imghandler/imghandler';
    import { File } from '@ionic-native/file/ngx';
    import { FileChooser } from '@ionic-native/file-chooser/ngx';
    import { FilePath } from '@ionic-native/file-path/ngx';
    import { RequestsProvider } from '../providers/requests/requests';
    import { ChatProvider } from '../providers/chat/chat';
    import { GroupsProvider } from '../providers/groups/groups';
    import { CommandProvider } from '../providers/command/command';


    @NgModule({
      declarations: [
        MyApp
      ],
      imports: [
        BrowserModule,
        IonicModule.forRoot(MyApp, {tabsPlacement: 'top'}),
        AngularFireModule.initializeApp(config)
      ],
      bootstrap: [IonicApp],
      entryComponents: [
        MyApp
      ],
      providers: [
        StatusBar,
        SplashScreen,
        {provide: ErrorHandler, useClass: IonicErrorHandler},
        AuthProvider,
        AngularFireAuth,
        UserProvider,
        ImghandlerProvider,
        FileChooser,
        File,
        FilePath,
        RequestsProvider,
        ChatProvider,
        GroupsProvider,
        CommandProvider
      ]
    })
    export class AppModule {}

А вот мои iportorts для функции, которую я указал выше

import { Injectable } from '@angular/core';
import { File } from '@ionic-native/file';
import { FileChooser } from '@ionic-native/file-chooser/ngx'
import { FilePath } from '@ionic-native/file-path';
import firebase from 'firebase';

Есть идеи, почему может возникнуть эта ошибка?

...