Uncaught (in promise): Error Cannot instantiate object new is missing

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

I have a controller:

Menu.Controller.js:

sap.ui.define([        "sapit/ext/utils/BaseController",        "sap/ui/model/json/JSONModel",        "sap/ui/model/Sorter",        "sap/ui/model/Filter",        "sapit/nova/model/constants",        "sapit/ nova /model/formatter",        "sapit/ nova /util/Helper",        "sapit/ nova /util/Validator",        "sapit/ nova /util/ItemService"      ], function(BaseController, JSONModel, Sorter, Filter, constants, formatter, Helper, Validator, ItemService) {        "use strict";         return BaseController.extend("sapit.nova.controller.Menu", {               formatter: formatter,              helper: new Helper(),              itemService: new ItemService(),                onInit: function() {                this.fragmentProcess = sap.ui.xmlfragment("sapit.nova.view.fragment.Process", this);                // attach events                this.getRouter().attachRouteMatched(jQuery.proxy(this.onRouteMatched, this));              },              onRouteMatched: function(oEvent) {                  var oPage = this.byId("menuProcessor");                  var sRouteName = oEvent.getParameter("name");                   if (sRouteName === "Menu") {                    // show fragment                    this.helper.clearFragment(oPage);                    this.helper.showFragment(oPage, this.fragmentProcess);                  }

I have the corresponding xml view as Menu.view.xml:

mvc:View controllerName="sapit.nova.controller.Menu" xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc">     <Page id="menuProcessor" title="{i18n>menuPageTitle}" showNavButton="false">      </Page> </mvc:View>

My router config is:

"routes": [{     "pattern": "/admin",     "name": "Main",     "target": ["menu"]   },    "targets": {     "menu": {       "viewName": "Menu",       "viewLevel": 1,       "controlAggregation": "masterPages"     }

The problem is when I run this application control is going to onInit () of the menu.controller but it's not going to onRouteMatched although it's getting the instance of router attached to this view.

Every time i run this application i am getting an Error after entering the onInit() and rest of code doesn't work and view doesn't come up.

Uncaught (in promise) Error: Cannot instantiate object: "new" is missing!     at constructor (sap-ui-core.js:640)     at constructor (sap-ui-core.js:1601)     at constructor (sap-ui-core.js:1571)     at f (sap-ui-core.js:638)     at f (sap-ui-core.js:284)     at p (sap-ui-core.js:285)     at _ (sap-ui-core.js:286)     at Object.properties (sap-ui-core.js:286)     at l (sap-ui-core.js:298)     at B.getText (sap-ui-core.js:296)

Can you please suggest me in this regard.

Thanks !!

回答1:

Remove the spaces from sap.ui.define this might be a problem when loading Helper, Validator and ItemService

sap.ui.define([         "sapit/ext/utils/BaseController",         "sap/ui/model/json/JSONModel",         "sap/ui/model/Sorter",         "sap/ui/model/Filter",         "sapit/nova/model/constants",         "sapit/ nova /model/formatter",         "sapit/ nova /util/Helper",         "sapit/ nova /util/Validator",         "sapit/ nova /util/ItemService"     ],


回答2:

You did not instantiate your fragment.

Try this :

this.fragmentProcess = new sap.ui.xmlfragment("sapit.nova.view.fragment.Process", this);


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