2

I'm trying to use filetransfer as a provider in my app, but I'm getting this problem.

"No provider for Transfer!"

I can't find the solution.

This is my code.

My provider

import { Injectable } from '@angular/core';
import { Transfer, FileUploadOptions, TransferObject } from '@ionic-native/transfer';
// import { File } from '@ionic-native/file';


    @Injectable()

        export class FileTransfer {

          options: FileUploadOptions = {}
          fileTransfer: any;

          constructor(private transfer: Transfer) {
            console.log('Hello FileTransfer Provider');

          }

I already imported my provider to the app.module

import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';

import { FileTransfer } from "../providers/file-transfer";

And added it to my providers in the same app.module

  providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler }, Storage, FileTransfer]

And finally, I'm importing the provider to my page.

import { Component } from '@angular/core';
import { FileTransfer } from '../../providers/file-transfer';

----

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public storage: Storage,
    public platform: Platform,
    public alertCtrl: AlertController,
    public modal: ModalController,
    public loadingCtrl: LoadingController,
    public fileTransfer: FileTransfer
  )

So i dont know, where the problem is, I hope, you can help me.

Thanks!!

Mystearica
  • 167
  • 1
  • 3
  • 12

2 Answers2

1

Try:

import { Transfer } from "../providers/file-transfer";

in your app.module. And,

providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler }, Storage, Transfer]

in your providers.

Baksa Gimm
  • 123
  • 9
0

The error is

"No provider for Transfer!"

Your import syntax is for ionic-native 2.8.1 here.

Change import to

import { Transfer} from '@ionic-native';

Or change ionic-native version to 2.8.1.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • If i do that, the code doesn't work. Sorry i think i said to you the wrong ionic-native. I have this ones https://i.imgur.com/gajNAJu.png – Mystearica Mar 21 '17 at 14:34
  • alright..check breaking changes https://github.com/driftyco/ionic-native/blob/ad8589b5f2342dc858382564a369572207e8b194/CHANGELOG.md – Suraj Rao Mar 21 '17 at 14:37
  • It has to be ionic native version.. you will have to figure out the right one where the new imports work..I use the old way with 2.4.1 if it matters – Suraj Rao Mar 21 '17 at 14:40
  • Why do you have both though? you have 2 sets of ionic native imports – Suraj Rao Mar 21 '17 at 14:48
  • I was reading the differences in 3.1.0, and just says that you need to import it the way i did, so i don't know :( – Mystearica Mar 21 '17 at 14:52
  • I dont know why i have 2 imports, I mean, i didnt touch anything, just installed file transfer, etc, thats it. – Mystearica Mar 21 '17 at 14:53
  • I guess you can remove the new ones and try with 2.4.1 or raise an issue at github..or remove the 2.4.1 entry in package.json and try? I havent tried 3.1.0 to tell you for certain – Suraj Rao Mar 21 '17 at 14:58
  • Anyway, maybe the problem is not the import itself, i have a line that i did it different, cause i receive an error that says that a ' A class member cannot have the 'const' keyword' in this line of code: const fileTransfer: TransferObject = this.transfer.create(); – Mystearica Mar 21 '17 at 15:03
  • Instead of using it as a provider, try to use filetransfer directly in your module and see if it works. If yes, there may be an issue in using it as a provider. – Deepak Mar 21 '17 at 17:36