Error: Unsupported event 'propertyChange': v4.ODataModel#attachEvent

34 Views Asked by At

Trying to attach a function to the method attachPropertyChange on the sap.ui.model.odata.v4.ODataModel

onAfterRendering: function () {
  var oModel = this.getView().getModel(); //based on sap.ui.model.odata.v4.ODataModel 
  oModel.attachPropertyChange(() => console.log("hello"));
}

in the console it appears:

enter image description here

Has the event PropertyChange been deprecated on sap.ui.model.odata.v4.ODataModel?

The model is defined in manifest.json file and it has the version 4.0

"dataSources": {
  "mainService": {
    "uri": "/sap/opu/odata4/sap/ui_sensitivefielditem/srvd/sap/ui_sensitivefielditem/0001/",
    "type": "OData",
    "settings": {
      "annotations": [
        "annotation"
      ],
      "localUri": "localService/metadata.xml",
      "odataVersion": "4.0"
    }
  },
  "annotation": {
    "type": "ODataAnnotation",
    "uri": "annotations/annotation.xml",
    "settings": {
      "localUri": "annotations/annotation.xml"
    }
  }
}
},


"models": {
  "i18n": {
    "type": "sap.ui.model.resource.ResourceModel",
    "settings": {
      "bundleName": "com.swisslife.vimsensitivefielditem.i18n.i18n"
    }
  },
  "": {
    "dataSource": "mainService",
    "preload": true,
    "settings": {
      "synchronizationMode": "None",
      "operationMode": "Server",
      "autoExpandSelect": true,
      "earlyRequests": true
    }
  },
2

There are 2 best solutions below

1
Boghyon Hoffmann On BEST ANSWER

The v4.ODataModel event propertyChange is available only since UI5 1.110.

Press Ctrl+Shift+Left Alt / Left-Option+P in the app to see with which UI5 version the app is running.

0
schuckspecht On

I just checked in a local SAPUI5 app, and the method does exist for me. How exactly are you creating your model in your manifest.json? What version of SAPUI5 are you currently using?