Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Uncaught (in promise) SyntaxError: Unexpected token 'const' in UI5 (SAP)

Hi I wanted to make an API Call in Ui5 but everytime it tells me, that it doesnt know whats ‘Const’.

Uncaught SyntaxError: Unexpected token ‘const’
The following error occurred while displaying routing target with name ‘TargetResult’: SyntaxError: Unexpected token ‘const’ –
Uncaught (in promise) SyntaxError: Unexpected token ‘const’

my Ui5 call:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sap.ui.define([
      "sap/ui/core/mvc/Controller", "sap/ui/model/json/JSONModel"
    ], function(Controller, JSONModel) {
      "use strict";

      return Controller.extend("TESTE.TESTE.controller.ResultDevice", {

            onInit: function() {
              var sUrl = "/api/tablets?limit=1000&offset=0";
              const url = "https://jsonplaceholder.typicode.com/users";

              fetch(url).then(res => res.json()).then(res => (
                  const dataModel = new JSONModel(); dataModel.setData({
                    items: res
                  }); this.getView().setModel(dataModel, "aribadevices")

                )
              },
            },

>Solution :

There are several issues with your curly braces and parenthesis. This code should work, doesn’t have syntax errors, and is a little easier to read with each expression being on a new line.

sap.ui.define([
    "sap/ui/core/mvc/Controller", "sap/ui/model/json/JSONModel"
  ], function(Controller, JSONModel) {
    "use strict";

    return Controller.extend("TESTE.TESTE.controller.ResultDevice", {

            onInit: function() {
            var sUrl = "/api/tablets?limit=1000&offset=0";
            const url = "https://jsonplaceholder.typicode.com/users";

            fetch(url).then(res => res.json()).then(res => {
                const dataModel = new JSONModel(); 
                dataModel.setData({
                    items: res
                }); 
                this.getView().setModel(dataModel, "aribadevices");
            })
        }
    })
});

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading