【发布时间】:2019-12-05 07:41:03
【问题描述】:
我正在使用 nativescript-camera 在我的 Android 应用程序中捕获图像,但我总是收到 TypeError: Cannot set property 'imageSource' of undefined。我正在按照指南here 进行操作,我所有的相机代码似乎都是正确的,但我不确定我在哪里做错了。
export class SocialRegistrationComponent implements OnInit {
imageSource: ImageSource;
constructor() {}
ngOnInit() {
}
capturePicture() {
const options = {
saveToGallery: false,
allowsEditing: false,
format: 'png'
};
camera.requestPermissions().then(
function success() {
camera.takePicture(options)
.then((capturedImageAsset) => {
let imageSource = new imageSourceModule.ImageSource;
imageSource.fromAsset(capturedImageAsset)
.then((capturedImageSource: ImageSource) => {
console.log(capturedImageSource); // Display correctly
this.imageSource = capturedImageSource; // Error here, this.imageSource undefined
});
}).catch((err) => {
console.log('Error -> ' + err.message);
});
},
function failure() {
// failed
}
);
}
}
【问题讨论】:
标签: angular android-camera nativescript nativescript-angular