Skip to Content
-1

ResouceModel not defined. how to resolve this problem

Dec 08, 2017 at 11:53 AM

78

avatar image
Former Member

Uncaught (in promise) ReferenceError: ResourceModel is not defined. App.controller.js?eval:21

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

6 Answers

Simon Perstorfer Dec 08, 2017 at 12:13 PM
0

Hi Zhang,

can you share more informations?

Regards
Simon

Share
10 |10000 characters needed characters left characters exceeded
Arjun Biswas Dec 09, 2017 at 03:39 AM
0

Hi Zhang pengfei,

Declare your resource model in your manifest file like this :

"models": {
			"i18ns": {
				"type": "sap.ui.model.resource.ResourceModel",
				"settings": {
					"bundleName": "sap.ui.myApp.i18n.i18n"
				}
			}
	},

Now in your controller, you can access your resource model and set it to your view like this :

this.getView().setModel(this.getOwnerComponent().getModel("i18ns"), "i18n");

In your view, you can use your resource model :

<Page title="{i18n>PAGE_TITLE}" id="page">
</Page>

Hope this helps,

Regards,

Arjun Biswas

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Dec 09, 2017 at 01:52 AM
0

when execute index.html, the controller module occur error: Uncaught (in promise) ReferenceError: ResourceModel is not defined

App.controller.js

  1. sap.ui.define([
  2. "sap/ui/core/mvc/Controller",
  3. "sap/m/MessageToast",
  4. "sap/ui/model/json/JSONModel",
  5. "sap/ui/model/resource/ResourceModel"
  6. ],function(Controller,MessageToast,JSONModel,ResouceModel){
  7. "use strict";
  8. return Controller.extend("sap.ui.demo.wt.controller.App",{
  9. onInit:function(){
  10. //set data on view
  11. var oData = {recipient:{name:"darling abc"}};
  12. var oModel = new JSONModel(oData);
  13. this.getView().setModel(oModel);
  14. //set i18n model on view
  15. var i18nModel = new ResourceModel({bundleName:"sap.ui.demo.wt.i18n.i18n"});
  16. this.getView().setModel(i18nModel,"i18n");
  17. },
  18. onShowHello:function(){
  19. //read msg from i18n model
  20. var oBundle = this.getView().getModel("i18n").getResourceBundle();
  21. var sRecipient = this.getView().getModel().getProperty("/recipient/name");
  22. var sMsg = oBundle.getText("helloMsg",[sRecipient]);
  23. //show message
  24. MessageToast.show(sMsg);
  25. }
  26. });
  27. });
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Dec 09, 2017 at 01:56 AM
0

ResourceModel should be the sapui5's library, i thought. i have reinstall the sapui5 plugin in eclipse neon(https://tools.hana.ondemand.com/neon), but error still exist.

Share
10 |10000 characters needed characters left characters exceeded
Irfan Gokak Dec 10, 2017 at 12:38 PM
0

Hi,

If you're using manifest.json then this answer(by Arjun Biswas) do work for you. You no need to set model manually in Component.js.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Dec 11, 2017 at 08:16 AM
0

Thank you very much! my problem has been gone by using Arjun Biswas teacher 's method.谢谢!

Share
10 |10000 characters needed characters left characters exceeded