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();
}
Restart your ionic application may clear this issue if everything is imported as expected
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With