[英]Issue at using cordova camera plugin within angular2
I try to get the cordova-plugin-camera running with a simple test component within angular2.我尝试使用 angular2 中的一个简单测试组件来运行 cordova-plugin-camera。
First I added the plugin to cordova by Installing the plugin at cordova.首先,我通过在cordova 上安装插件将插件添加到cordova。 Following, I added at the index.html the cordova.js.
接下来,我在 index.html 中添加了cordova.js。
<body>
<app-root>Loading...</app-root>
<script type="text/javascript" src="cordova.js"></script>
</body>
After that I build a simple angular component where to call the cordova plugin.之后,我构建了一个简单的 angular 组件来调用cordova 插件。 This component has a button and this button should call the native camera via cordova.
这个组件有一个按钮,这个按钮应该通过cordova调用原生相机。
Componenten HTML
<p>
testcamera works!
</p>
<div>
<button md-raised-button (click)="takePicture()">Picture</button>
</div>
By clicking the method/function on the component will be called.通过单击组件上的方法/函数将被调用。 I declared a cordova variable to have access to the cordova plugins.
我声明了一个cordova变量来访问cordova插件。
Angular component TS角分量 TS
import { Component, OnInit } from '@angular/core';
declare let cordova: any;
@Component({
selector: 'app-testcamera',
templateUrl: './testcamera.component.html',
styleUrls: ['./testcamera.component.css']
})
export class TestcameraComponent implements OnInit {
public base64Image : String;
public photos;
public text;
constructor() {
}
ngOnInit() {
}
takePicture(){
cordova.plugins.camera.getPicture({
destinationType: cordova.plugins.camera.DestinationType.DATA_URL,
targetWidth: 1000,
targetHeight: 1000
}).then((imageData) => {
// imageData is a base64 encoded string
this.base64Image = "data:image/jpeg;base64," + imageData;
}, (err) => {
console.log(err);
});
}
}
The component works so fare but when I push the button "Picture" the function get called but the cordova does not open the native picture application.该组件可以正常工作,但是当我按下“图片”按钮时,该函数会被调用,但cordova 不会打开本机图片应用程序。 The calling cordova.plugins.camera.getPicture(..) not working.
调用cordova.plugins.camera.getPicture(..) 不起作用。 Can anyone help on that?
任何人都可以帮忙吗? What am I missing?
我错过了什么? Thanks a lot in advance.
非常感谢。
Okay I help myself.好吧,我帮助自己。 The Problem I had was that I was taken the wrong variable.
我遇到的问题是我选择了错误的变量。
Instead of而不是
destinationType: cordova.plugins.camera.DestinationType.DATA_URL,
目的地类型:cordova.plugins.camera.DestinationType.DATA_URL,
I add to take the follwoing:我补充一下:
destinationType: navigator.camera.DestinationType.DATA_URL,
目的地类型:navigator.camera.DestinationType.DATA_URL,
Also for that I had to declare a variable for it.同样为此,我必须为它声明一个变量。
declare let navigator: any;`
声明让导航器:任何;`
Thx a lot `非常感谢`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.