Hello Expert,
I created a fragment and i can attach it to view using <core:Fragment fragementName="view.frg" type="XML" />
Now i can see the fragment in the view.
My requirement is to have controller for each created fragment.
I am following below link to get the details
JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui
But i am not able to link the controller to the fragement. Please guide me to define the controller for each fragment.
Fragment:
<core:FragmentDefinition xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:core="sap.ui.core">
<VBox>
<items>
<Text text="This dialog is from XML fragment" />
<Button text="Clickme" press="onClick" />
</items>
</VBox>
</core:FragmentDefinition>
controller for fragment i have defined as:
sap.ui.define([
"sap/ui/controller"
], function(Controller) {
"use strict";
return Controller.extend("bind.controller.test", {
onInit: function() {
alert("test");
},
onClick: function(){
alert("Thanks");
}
});
});
Thanks,
Abhi
Request clarification before answering.
Hello Everyone,
Any help is highly appreciated!
Thanks,
Abhi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Abhi,
you can assign a specific controller to a fragment when you programmatically instantiate the fragment in your view controller
sap.ui.define([
"sap/ui/core/mvc/Controller",
"Testing/controller/myFragmentController"
], function(Controller, FragmentController) {
"use strict";
return Controller.extend("Testing.controller.App", {
onInit: function() {
//Create new fragment with own controller
var oFragmentController = new FragmentController();
var oFragment = sap.ui.xmlfragment("Testing.view.myFragment", oFragmentController);
this.getView().byId("myPage").addContent(oFragment);
}
});
});
Here a plunker that shows how you can do it:
Thank you so much Francesco.
This is working as expected.
Just a clarification: So all created fragments (with fragment controller) has to be included to the view programetticaly and not with static like <core:Fragment /> direclty to view ?
If we add the fragment direclty to xml view with <core:Fragment /> then we cannot add controller to it? ( I just did it and function was not getting called from fragment controller ).
Many Thanks for your input.
Abhi
Although this is marked as answered, I'm not able to locate where the answer is. Can the author or someone help?
| User | Count |
|---|---|
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.