typescript 离子服务后,无法解析 [object OBJECT] 的所有参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43731327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
can't resolve all parameters for [object OBJECT], after ionic serve
提问by J.Rem
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],?"
不知道我做错了什么,但是在尝试使用 ionic 和 Cordova 插件时,我在 ionic serve 后收到以下错误:“无法解析 [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();
}
回答by Iris_geek
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.
我不知道这是否是正确的解决方案,但解决了我的问题。
回答by Miroslav Jonas
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.
解决方案是使用@Inject
声明。
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()
.
另外,重要的是说CameraPreview
本身应该用@Injectable()
.
@Injectable()
export class CameraPreview
// ... your code
}
回答by Imran
Restart your ionic application may clear this issue if everything is imported as expected
如果一切都按预期导入,重新启动您的离子应用程序可能会清除此问题