错误TS2339:类型“导航器”上不存在属性“照相机”

时间:2019-04-10 18:56:33

标签: angular typescript ionic-framework ionic4 navigator

我正在尝试构建一个可拍照的Ionic应用程序。 但是当我运行程序时,出现“错误TS2339:类型”导航器”上不存在属性“相机”

我已安装php artisan migrate --path=database/migrations/2019_04_10_migration_name.phpionic cordova plugin add cordova-plugin-camera

这是我的app.module.ts:

npm install @ionic-native/camera

这是我的home.page.ts

import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { RouteReuseStrategy } from "@angular/router";

import { IonicModule, IonicRouteStrategy } from "@ionic/angular";
import { SplashScreen } from "@ionic-native/splash-screen/ngx";
import { StatusBar } from "@ionic-native/status-bar/ngx";

import { AppComponent } from "./app.component";
import { AppRoutingModule } from "./app-routing.module";
import { Camera } from "@ionic-native/camera/ngx"; 

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
  providers: [
    Camera,
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

1 个答案:

答案 0 :(得分:0)

但是,为什么要使用navigator.camera.getPicture()

您必须使用this关键字来访问相机对象,然后才能调用getPicture()之类的this.camera.getPicture()方法。