Mystearica
Mystearica

Reputation: 167

Ionic2 filetransfer - No provider for Transfer

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

Upvotes: 2

Views: 4124

Answers (2)

Baksa Gimm
Baksa Gimm

Reputation: 123

Try:

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

in your app.module. And,

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

in your providers.

Upvotes: 1

Suraj Rao
Suraj Rao

Reputation: 29614

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.

Upvotes: 0

Related Questions