Uncaught TypeError: Fragment.load is not a function

故事扮演 提交于 2020-05-15 09:47:09

问题


The code below has been copied from UI5 Demo Kit but while I run it, the console is showing the error message that the function Fragment.load is not a function. Please suggest any alternative or highlight issue if any.

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

  return Controller.extend("Workspace.controller.HelloPanel", {
    onInit: function() {
      var plant = {
        pid: "",
        ptype: "",
        pdesc: "",
        psite: "",
        pstatus: "",
        passigned: "",
        pattach: ""
      };
      var oModel1 = new JSONModel(plant);
      this.getView().setModel(oModel1, "SUP");
    },

    onOpenDialog: function() {
      var oView = this.getView();
      if (!this.byId("helloDialog")) {
        Fragment.load({
          id: oView.getId(),
          name: "Workspace.view.HelloDialog",
          controller: this
        }).then(function(oDialog) {
          // connect dialog to the root view of this component (models, lifecycle)
          oView.addDependent(oDialog);
          oDialog.open();
        });
      } else {
        this.byId("helloDialog").open();
      }
    },

    onCloseDialog: function() {
      this.byId("helloDialog").close();
    },

  });
});

回答1:


For other readers: if you're getting the same error, keep in mind that Fragment.loadapi is available only as of 1.58.

To see which UI5 version the app is runnig with, press Ctrl+Shift+Left Alt+P.



For the question author: you have required the module "sap/m/MessageToast" twice.

sap.ui.define([
  "sap/ui/core/mvc/Controller",
  "sap/m/MessageToast",
  "sap/ui/model/Filter",
  "sap/ui/model/FilterOperator",
  "sap/ui/model/json/JSONModel",
  "sap/m/MessageToast", // <-- Remove it
  "sap/ui/core/Fragment"
], /*...*/);

The 2nd MessageToast needs to be removed. Otherwise, you're trying to call .load() from a MessageToast, hence the error.



来源:https://stackoverflow.com/questions/55287847/uncaught-typeerror-fragment-load-is-not-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!