title: Pass another controller when instantiating a fragment in SAPUI5
body: <p>In the SAPUI5 / OpenUI5 <a href="https://sapui5.netweaver.ondemand.com/sdk/docs/api/symbols/sap.ui.html#.xmlfragment" rel="nofollow noreferrer">xmlfragment documentation</a> the third parameter is a controller for handling actions from the fragment.</p>
  
  <p>This is critical for a dialog fragment where there are buttons to press etc.</p>
  
  <p>Most of the time I have seen this instantiated as <code>this</code> or <code>sap.ui.getCore().byId('&lt;element&gt;').getController())</code></p>
  
  <p>See an example at <a href="https://stackoverflow.com/questions/25203225/fragment-not-get-correct-controller">Fragment not get correct Controller</a></p>
  
  <p>Because of the complexity in a particular dialog I would like to have a separate controller for it. </p>
  
  <p>I have looked around at this and had a few attempts but so far not successful.</p>
  
  <p>I have put a working example on <a href="https://github.com/njames/DialogTest" rel="nofollow noreferrer">github</a> of using <code>this</code>. </p>
  
  <p>But I would like to instantiate <code>Dialog.js</code> as the controller for the <code>Dialog.fragment.xml</code> from <code>initial.view.controller</code> </p>
  
  <p>Any takers?</p>
  
  <p>Pull requests gladly received.</p>
  
  <p>The Crux of the example is as follows (this is the initial.controller.js) : </p>
  
  <pre><code>sap.ui.controller("sc.test.view.initial", {
  
  oDialog: null,
  
  openTestDialog: function(){
      console.log("in open dialog");
       // instantiate the other controller
       var oDialogController = new sc.test.view.Dialog();
      // this next commented line is the 'normal' way to do it
      // oDialog = new sap.ui.xmlfragment( "sc.test.view.Dialog", this);  //oDialogController);
      // this is what I would like to achieve
      oDialog = new sap.ui.xmlfragment( "sc.test.view.Dialog", oDialogController);
      oDialog.open();
  },       
  
  
  onCartDialogCancel:function(oEvent){
  // this function would then be in the other controller but how to get a handle on the dialog?
      oDialog.close();
  
  }
  </code></pre>
  
  <p>});</p>
  
  <p>Thanks.</p>