[英]“this.getService is not a function” when changing SAP Fiori title dynamically
I am trying to change SAP Fiori title dynamically ie after launchpad is launched and after I clicked on my app of choice, the title of the app should change based on what I want it to be.我正在尝试动态更改 SAP Fiori 标题,即在启动板启动后并单击我选择的应用程序后,应用程序的标题应根据我想要的更改。 I am using this doc page as a guide https://ui5.sap.com/1.54.3/docs/api//symbols/sap.ushell.ui5service.ShellUIService.html .
我将此文档页面用作指南https://ui5.sap.com/1.54.3/docs/api//symbols/sap.ushell.ui5service.ShellUIService.html 。
Inside my webapp/Component.js
, I have my setAppTitle()
method which should set a new custom title to the app, and is called from within onAfterRendering()
method of webapp/view/S2Custom.controller.js
.在我的
webapp/Component.js
中,我有我的setAppTitle()
方法,它应该为应用程序设置一个新的自定义标题,并从webapp/view/S2Custom.controller.js
的onAfterRendering()
方法中调用。
The reason, why I can not call setAppTitle()
directly from within init()
method of webapp/Component.js
, is because I am getting my titles from webapp/i18n/i18n.properties
which is not "loaded" yet during Component.js
's init()
.为什么我不能直接从
webapp/Component.js
的init()
方法中调用setAppTitle()
的原因是因为我从webapp/i18n/i18n.properties
获取我的标题,它在Component.js
的init()
。
To avoid using something like setTimeout(() => this.setAppTitle(sTitle), 6000)
inside Component.js
, I decided to call it from within onAfterRendering()
method of webapp/view/S2Custom.controller.js
.为了避免在
Component.js
中使用setTimeout(() => this.setAppTitle(sTitle), 6000)
之类的东西,我决定从webapp/view/S2Custom.controller.js
的onAfterRendering()
方法中调用它。
onAfterRendering: function (oEvent) {
var sComponentId = sap.ui.core.Component.getOwnerIdFor(this.getView());
var oComponent = sap.ui.component(sComponentId);
var i18nModel = new sap.ui.model.resource.ResourceModel({
bundleName: "ui.s2p.srm.sc.blahblah.BlahBlahExtension.i18n.i18n"
});
var oResource = i18nModel.getResourceBundle();
var sTitle = oComponent.getModel("appModel").getProperty("/sMode") === "OUTBOX" ? oResource.getText("APP_ONE") : oResource.getText("APP_TWO");
this.getOwnerComponent().setAppTitle(sTitle);
},
setAppTitle: function (sText) {
var sTitle = sText;
console.log("TEST: ", this.getService("ShellUIService")); // ERROR !!!
try {
this.getService("ShellUIService").then(function (oService) {
oService.setTitle(sTitle);
}, function (oError) {
jQuery.sap.log.error("Cannot get ShellUIService");
});
} catch (err) {
console.log("TEST - ERROR: ", err);
}
},
The issue in setAppTitle()
method - the console shows an error: setAppTitle()
方法中的问题 - 控制台显示错误:
this.getService is not a function.
this.getService 不是 function。
So I went into my manifest.json
所以我进入了我的
manifest.json
"sap.ui5": {
"_version": "1.2.0",
"services": {
"ShellUIService": {
"factoryName": "sap.ushell.ui5service.ShellUIService"
}
},
"dependencies": {
"minUI5Version": "1.28.5",
"libs": {}
},
I noticed Web IDE showed Property "services" is not allowed error on line which contains "services": {
.我注意到 Web IDE 在包含“服务”的行上显示属性“服务”不允许错误
"services": {
。
Can you tell me what's causing this problem?你能告诉我是什么导致了这个问题吗? I already tried calling
this.getService("ShellUIService")
alone inside Component.js
's init()
method, unfortunately the same error我已经尝试在
Component.js
的init()
方法中单独调用this.getService("ShellUIService")
,不幸的是同样的错误
this.getService is not a function.
this.getService 不是 function。
You must be using an old UI5 version.您必须使用旧的 UI5 版本。 The API
component.getService
is available only as of 1.37.0
: API
component.getService
仅从1.37.0
可用:
You can check your current version by pressing Ctrl + Left Alt + Shift + P in the app.您可以通过在应用程序中按Ctrl + Left Alt + Shift + P检查当前版本。
About the Web IDE error message..关于 Web IDE 错误信息..
I noticed Web IDE showed Property "services" is not allowed error on line which contains
"services": {
.我注意到 Web IDE 在包含“服务”的行上显示属性“服务”不允许错误
"services": {
。
_version
, remove all other _version
s in sap.app
, sap.ui5
, etc.._version
,删除sap.app
、 sap.ui5
等中的所有其他_version
。_version
to something higher than 1.3.0
according to the table AppDescriptor Release and SAPUI5 Version ._version
设置为高于1.3.0
的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.