title: Dismiss $uibModal from within
body: <p>I'm using Bootstrap's $uibModal to make forms in my web-application. Everything works fine, except that I cannot close the dialog after it's been shown.</p>
  
  <p>I spent two days trying not to post here such a simple question, especially when there was a lot of answers for the same error that I'm receiving, i.e.</p>
  
  <blockquote>
    <p>"<strong>Unknown provider: $uibModalInstanceProvider &lt;- $uibModalInstance &lt;-
    ModalInstanceCtrl</strong>".</p>
  </blockquote>
  
  <p>To have some ease in operating with huge application, I divided my code into separate files, also I use 'controller as' style in htmls, so, there's no $scopes in the code.</p>
  
  <p>No matter what I do, I keep receiving this error that I mentioned before.
  What I need, is to close the dialog after user have successfully logged in.</p>
  
  <p><strong>index.html:</strong></p>
  
  <pre><code>...
      &lt;script src="rf/angular.min.js"&gt;&lt;/script&gt;
      &lt;script src="rf/angular-animate.js"&gt;&lt;/script&gt;
      &lt;script src="rf/angular-touch.js"&gt;&lt;/script&gt;
      &lt;script src="rf/ui-bootstrap-tpls.js"&gt;&lt;/script&gt;
  
      &lt;!-- Project files --&gt;
      &lt;script src="application.js" type="text/javascript"&gt;&lt;/script&gt; 
      &lt;script src="frmLogin.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;!-- Load things into this division --&gt;
      &lt;div ng-include src="loaderCtrl.cFragment" ng-app="dgis" ng-controller="applicationController as loaderCtrl"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p><strong>application.js</strong></p>
  
  <pre><code>var myApp = angular
    .module('dgis', ['ui.bootstrap'])
    .controller("applicationController", ['$http', '_gl', '$uibModal', function ($http, _gl, $uibModal) {
        _gl.AppReference = this;
  
        // Enable animations
        this.animationsEnabled = true;
  
        // Declare modal window
        this.showFrmLogin = function (size) {
           var modalInstance = $uibModal.open({
                animation: this.animationsEnabled,
                templateUrl: 'frmLogin.html',
                controller: 'ModalInstanceCtrl',
                size: size,
                backdrop: 'static',
                keyboard: false,
                resolve: {
                    items: function () {
                        return this.items;
                    }
                }
            });
        };
  
        this.showFrmLogin();
  </code></pre>
  
  <p><strong>frmLogin.js</strong></p>
  
  <pre><code>myApp.controller('ModalInstanceCtrl', ['_gl', '$uibModalInstance', function (_gl, $uibModalInstance) {
  
      this.login = function () {        
          angular.forEach(some_array, function (element) {
              if (something == element)                   
                 // This code executes successfully and shows the page
                 _gl.AppReference.cFragment = "frmMain.html";
                 // This line does not close the dialog
                 $uibModalInstance.close('a');
              }
          });
      }
  }]);
  </code></pre>
  
  <p>And <strong>_gl</strong> - is a service that I use to hold global variables</p>