2
votes

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!!

2
which version of ionic-native version are you using? - Suraj Rao
"ionic-native": "^2.4.1", - Mystearica

2 Answers

1
votes

Try:

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

in your app.module. And,

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

in your providers.

0
votes

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.