Skip to Content
avatar image
-1
Former Member

ResouceModel not defined. how to resolve this problem

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Dec 08, 2017 at 12:13 PM

    Hi Zhang,

    can you share more informations?

    Regards
    Simon

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 09, 2017 at 03:39 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 09, 2017 at 01:52 AM

    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. });
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 09, 2017 at 01:56 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 10, 2017 at 12:38 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 11, 2017 at 08:16 AM

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

    Add comment
    10|10000 characters needed characters exceeded