Search code examples
ionic-frameworkcordova-pluginsionic4

Ionic 4 cordova-plugin-ftp issues after adding to constructor


I am trying to get the cordova-plugin-ftp plugin to work with ionic 4 so this is what I've done:

created a new project:

ionic start myproject

then cd into it and added the plugin:

ionic cordova plugin add cordova-plugin-ftp
npm install @ionic-native/ftp

Then go to my home.page.ts and imported the plugin:

import { FTP } from '@ionic-native/ftp/ngx';

Then added it to the contructor:

constructor(private ftp: FTP) {}

Here's the whole .ts code:

import { Component } from '@angular/core';
import { FTP } from '@ionic-native/ftp/ngx';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {

  constructor(private ftp: FTP) {}

}

As soon as a do the above I get a blank page:

I get this in the console:

ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[HomePage -> FTP]: 
  StaticInjectorError(Platform: core)[HomePage -> FTP]: 
    NullInjectorError: No provider for FTP!
NullInjectorError: StaticInjectorError(AppModule)[HomePage -> FTP]: 
  StaticInjectorError(Platform: core)[HomePage -> FTP]: 
    NullInjectorError: No provider for FTP!

What is the problem and how can I fix this?


Solution

  • Please check if you have imported the FTP module in app.module.ts file or not. If not then you need to import it first, since the app is not able to import the FTP module from the root since it was added externally.

    You also need to add it in providers list in app.module.ts.