Skip to Content
author's profile photo Former Member
Former Member

getView() is not working in controller

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");

}

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Jul 25, 2016 at 03:39 PM

    Hi Rangaswamy,

    Try something like below:

    capturePhoto : function() { 
        var oNav = navigator.camera; 
        oNav.getPicture($.proxy(this.onPhotoDataSuccess, this), $.proxy(this.onFail, this), { quality: 10, destinationType: oNav.DestinationType.DATA_URL });
        this._getDialog1().close(); 
        }
    

    Regards,

    Sai.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 25, 2016 at 03:39 PM

    put this.onPhotoDataSuccess.bind(this) in capturePhoto

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.