Search code examples
sapui5

Accessing control value fails due to TypeError: Cannot read property 'getView' of undefined


I've created a checkbox and set its default value to true. on that checkbox select, even I can get the value of that checkbox, either it's checked or not. But from other methods in controller, how I can get the value? I tried different ways but still unable to get value.

onChangeCheckbox: function(event){
  var value = this.byId("chkMyTest").getSelected();
}

Uncaught (in promise) TypeError: Cannot read property 'byId' of undefined


Solution

  • If you are using XML views, then it should be:

    var value = this.byId("chkMyTest").getSelected();
    

    Where this refers to your controller.