Angular 无法获取属性';目的类型';ionic 3中未定义或空引用的

Angular 无法获取属性';目的类型';ionic 3中未定义或空引用的,angular,ionic-framework,Angular,Ionic Framework,我是爱奥尼亚应用程序的初学者,我正在尝试使用下面的代码捕获pic,但我遇到了异常,如无法获取未定义或空引用的属性“DestinationType”,我在我的项目中添加了以下两个插件 有人能帮我吗 $ionic cordova插件添加cordova插件相机预览 $npm安装--保存@ionic native/camera预览 home.ts: home.html: 您可能想使用Camera而不是CameraPreview。 您必须使用Angular的依赖项注入将相机的一个实例注入组件。将摄像头添加

我是爱奥尼亚应用程序的初学者,我正在尝试使用下面的代码捕获pic,但我遇到了异常,如无法获取未定义或空引用的属性“DestinationType”,我在我的项目中添加了以下两个插件

有人能帮我吗

$ionic cordova插件添加cordova插件相机预览 $npm安装--保存@ionic native/camera预览

home.ts: home.html: 您可能想使用Camera而不是CameraPreview。 您必须使用Angular的依赖项注入将相机的一个实例注入组件。将摄像头添加到构造函数中(并删除
公共摄像头:摄像头

你可以按照爱奥尼亚的方法来做


您可以阅读。

因为您使用了
cordova插件相机预览

$ ionic cordova plugin add cordova-plugin-camera-preview
$ npm install --save @ionic-native/camera-preview
您需要导入

import { CameraPreview } from '@ionic-native/camera-preview';
下面是一个
示例

import { CameraPreview, CameraPreviewPictureOptions, CameraPreviewOptions, CameraPreviewDimensions } from '@ionic-native/camera-preview';

constructor(private cameraPreview: CameraPreview) { }


// camera options (Size and location). In the following example, the preview uses the rear camera and display the preview in the back of the webview
const cameraPreviewOpts: CameraPreviewOptions = {
  x: 0,
  y: 0,
  width: window.screen.width,
  height: window.screen.height,
  camera: 'rear',
  tapPhoto: true,
  previewDrag: true,
  toBack: true,
  alpha: 1
};

// start camera
this.cameraPreview.startCamera(cameraPreviewOpts).then(
  (res) => {
    console.log(res)
  },
  (err) => {
    console.log(err)
  });


}
然后将
CameraPreview
添加到
app模块中的提供者中

import { CameraPreview } from '@ionic-native/camera-preview';

...

@NgModule({
  ...

  providers: [
    ...
    CameraPreview
    ...
  ]
  ...
})
export class AppModule { }

公共摄像机:摄像机;相机是一个界面吗?如果是的话,你能粘贴相机的代码吗?否则,您必须定义一个接口并分配它。@Jacob Nelson我编辑了我的代码,我现在遇到异常-->未捕获(承诺中):错误:StaticInjectionError(AppModule)[HomePage->Camera];StaticInjectionError(平台:core)我认为您需要导入
而不是
摄像头
,而不是
摄像头
?我添加了请立即检查未捕获(承诺):错误:StaticInjectionError(AppModule)[主页->摄像头];StaticInjectionError(Platform:core)当我更新为您的SaidId时,我遇到上述异常。您是否从app.module.ts将摄像头添加到提供商阵列中,如此处所述?“由模块“AppModule”声明的“摄像头”。请添加@Pipe/@Directive/@组件注释。@AbhiRam,尝试添加
CameraPreview
而不是
camera
。请检查我的答案一次。模块“AppModule”声明了意外值“CameraPreview”。请添加@Pipe/@Directive/@组件注释。获取此例外您可以添加您的
应用程序模块
?不,我认为
摄像头
只能在移动设备中工作,因为它是
本机插件
$ ionic cordova plugin add cordova-plugin-camera-preview
$ npm install --save @ionic-native/camera-preview
import { CameraPreview } from '@ionic-native/camera-preview';
import { CameraPreview, CameraPreviewPictureOptions, CameraPreviewOptions, CameraPreviewDimensions } from '@ionic-native/camera-preview';

constructor(private cameraPreview: CameraPreview) { }


// camera options (Size and location). In the following example, the preview uses the rear camera and display the preview in the back of the webview
const cameraPreviewOpts: CameraPreviewOptions = {
  x: 0,
  y: 0,
  width: window.screen.width,
  height: window.screen.height,
  camera: 'rear',
  tapPhoto: true,
  previewDrag: true,
  toBack: true,
  alpha: 1
};

// start camera
this.cameraPreview.startCamera(cameraPreviewOpts).then(
  (res) => {
    console.log(res)
  },
  (err) => {
    console.log(err)
  });


}
import { CameraPreview } from '@ionic-native/camera-preview';

...

@NgModule({
  ...

  providers: [
    ...
    CameraPreview
    ...
  ]
  ...
})
export class AppModule { }