Skip to Content
0
Former Member
Jul 25, 2016 at 03:26 PM

getView() is not working in controller

694 Views

Hi experts,

here i am working on camera functionality.

i have image control in view and button, when i click on button image should place in image control.

for this functionality i listed below. but here i am facing the issue with var oView = this.getView();

When i running the application it is showing "Uncaught TypeError: Cannot read property 'getView' of null".

if var oView = this.getView(); is outside of the onPhotoDataSuccess call back function, oView is getting instance of the view, but it is not getting in call back function of onPhotoDataSuccess.

can any one suggest how can i get view reference in onPhotoDataSuccess function.

and tell me any other alternate solution for this.

Detail.view.xml:

<Image id="myImage" width="200px" height="200px" />

<Button text="get photo" press="capturePhoto" />

Detail.controller.js:

capturePhoto : function() {

var oNav = navigator.camera;

oNav.getPicture(this.onPhotoDataSuccess, this.onFail, { quality: 10, destinationType: oNav.DestinationType.DATA_URL });

this._getDialog1().close();

}

onPhotoDataSuccess : function(imageData) {

var oView = this.getView(); // error in this line

var img = oView.byId("myImage");

img.setSrc("data:image/jpeg;base64," + imageData);

MessageToast.show("Photo have been Added Successfully");

}