Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Blocks (sap.uxap), how to add the associated controller?

Hi all, I need to attach a controller to a block. I need an html control element within the block, and I need to reference it from a controller (this.getView().byId("main").setContent(content) ) .


I created the block folder in the source control of the application. I added a BlockName.js which extends BlockBase. I added a BlockName.view.xml view too. But now, I need to attach a controller to this view.

The view shown well, but when I add this line in the BlockName.view.xml for add the associated controller:


     controllerName="sap.ui.demo.myFiori.block.GoalsBlock"


It gives an error in Chrome and the console displays the following error:

    

     Uncaught Error: Controller sap.ui.demo.myFiori.block.GoalsBlock couldn't be instantiated


block Folder:


BlockName.js


jQuery.sap.declare("sap.ui.demo.myFiori.block.BlockName");

jQuery.sap.require("sap.uxap.BlockBase");

sap.uxap.BlockBase.extend("sap.ui.demo.myFiori.block.BlockName", {

    metadata: {

        views: {

            Collapsed: {

                viewName: "sap.ui.demo.myFiori.block.BlockName",

                type: "XML"

            },

            Expanded: {

                viewName: "sap.ui.demo.myFiori.block.BlockName",

                type: "XML"

            }

        }

    }

});

BlockName.view.xml

<core:View

controllerName="sap.ui.demo.myFiori.block.BlockNameController"

xmlns:core="sap.ui.core"

xmlns="sap.m">

<Label text="Test"/>

<core:HTML id="main">

      </core:HTML>

</core:View>

BlockNameController.controller.js

............................



Thanks

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question