Я хочу использовать «Камера» в моем приложении ioni c. Скомпилировано успешно, но произошла ошибка. Uncaught TypeError: Object (...) не является функцией. Я не знаю, что это значит .. Пожалуйста, помогите мне ... board.page. html -> btnTakePicture () -> board.page.ts -> btnTakePiture () -> cameraService-> takePircture ()
app.module.ts
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';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
Camera
],
bootstrap: [AppComponent]
})
export class AppModule {}
board.page. html
<ion-header>
<ion-toolbar>
<ion-title>board</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<div>
<div>
<ul>
<li (click)="btnTakePicture()"><a class="button button-icon icon ion-camera"></a></li>
</ul>
</div>
</div>
</ion-content>
board.page.ts
import { Component, OnInit } from '@angular/core';
import {CameraService} from '../services/camera.service';
@Component({
selector: 'app-board',
templateUrl: './board.page.html',
styleUrls: ['./board.page.scss'],
})
export class BoardPage implements OnInit {
constructor(private cameraService: CameraService) { }
ngOnInit() {
}
btnTakePicture() {
this.cameraService.takePicture();
}
}
camera.service .ts
import { Injectable } from '@angular/core';
import {Camera, CameraOptions} from '@ionic-native/camera';
@Injectable({
providedIn: 'root'
})
export class CameraService {
public photos: any;
private base64Prefix = 'data:image/jpeg;base64,';
constructor(private camera: Camera) {
this.photos = [];
}
takePicture() {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
};
this.camera.getPicture(options).then((imageData) => {
const safeUrl: any = this.base64Prefix + imageData;
this.photos.push(safeUrl);
this.photos.reverse();
}, (err) => {
console.log('Camera issue: ' + err);
});
}
}