Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't resolve all parameters for [object OBJECT], after ionic serve

not sure what I'm doing wrong, but when trying to use ionic and Cordova plugins I receive the following error after ionic serve: "can't resolve all parameters for [object OBJECT],[object OBJECT],[object OBJECT],[object OBJECT],[object OBJECT],?"

import { Component, Injectable } from '@angular/core';
import { NavController } from 'ionic-angular';
import { ToastController } from 'ionic-angular';
import { File } from '@ionic-native/file';
import { Diagnostic } from '@ionic-native/diagnostic';
import { CameraPreview, CameraPreviewOptions, CameraPreviewDimensions} from '@ionic-native/camera-preview';
declare var cordova: any;

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
  providers: [CameraPreview, Diagnostic]
})
export class HomePage {

  constructor(
    public navCtrl: NavController,
    public toastCtrl: ToastController,
    public file:File,
    public diagnostic:Diagnostic,
    public cameraPreview: CameraPreview,
    public previewRect: CameraPreviewOptions
    ) {
    this.checkPermissions();
  }
like image 359
J.Rem Avatar asked May 02 '17 06:05

J.Rem


3 Answers

Restart your ionic application may clear this issue if everything is imported as expected

like image 54
Imran Avatar answered Nov 14 '22 17:11

Imran


I got the same issue somewhere, so I removed the last parameter of constructor and given it before constructor. In your case like this,

export class HomePage {

 public previewRect: CameraPreviewOptions;

 constructor(
  public navCtrl: NavController,
  public toastCtrl: ToastController,
  public file:File,
  public diagnostic:Diagnostic,
  public cameraPreview: CameraPreview   
 ) {
  this.checkPermissions();
 }
}

I don't know if this is the right solution but resolved my issue.

like image 34
Iris_geek Avatar answered Nov 14 '22 18:11

Iris_geek


This is a less known angular dependency issue, where compiler is unable to untangle the dependency tree.

The solution is to use @Inject with declarations.

export class HomePage {

  constructor(
    public navCtrl: NavController,
    public toastCtrl: ToastController,
    public file:File,
    public diagnostic:Diagnostic,
    @Inject(CameraPreview) public cameraPreview: CameraPreview   
  ) {
    this.checkPermissions();
  }
}

With this you are saying to compiler that missing class will be injected at later point.

Also, important is to say that CameraPreview itself should be decorated with @Injectable().

@Injectable()
export class CameraPreview
  // ... your code
}
like image 3
Miroslav Jonas Avatar answered Nov 14 '22 16:11

Miroslav Jonas