title: Angular $md-dialog controller from external file
body: <p>Im using md-dialog from Material Design and I came across a small issue which causes me a lot of trouble.</p>
  
  <p>I'm using this dialog as a form for creating a new record in db and I need its controller to be loaded from external file. The reason is that I'm using the same dialog in many places of the app (in many other controllers) and I dont want to copy and paste it to each one of them. </p>
  
  <p>I've tried to write it as a service, but the problem is, as I'm binding data from form to the controller I'm using $scope and that way i got "$scope is not defined". When I add $scope as dependencies in that service, I'got injection error.
  Do you have any ideas how to load modal controller externally so it will work even with using of $scope? </p>
  
  <pre><code>$scope.showNewContactDialog = function($event) {
              var parentEl = angular.element(document.body);
                  $mdDialog.show({
                  parent: parentEl,
                  targetEvent: $event,
                  templateUrl: 'app/Pages/directory/contacts/newContact.dialog.html',
                  controller: NewCompanyContactDialogCtrl,
                  clickOutsideToClose: true,
                  hasBackdrop: true
              });  
          };
  
  // New User dialog controller
          function NewCompanyContactDialogCtrl($scope, $mdDialog) {
              var self = this;
              $scope.modalIcon = "add";
              $scope.modalTitle = 'Nová položka';
              $scope.modalAdvanced = true;
  
              // Country Selector
              apiCalls.getData(countryUrl, function(response){
                  $scope.countries = response;
              })
  
              // Add New Object
              $scope.newItem = function() {
                  var url = baseUrl + 'new/';
                  var data = JSON.stringify({
                      code: $scope.newItem.contactCode,
                      first_name: $scope.newItem.contactFirstName,
                      last_name: $scope.newItem.contactLastName,
                      street: $scope.newItem.contactStreet,
                      city: $scope.newItem.contactCity,
                      country: $scope.newItem.contactCountry,
                      postal: $scope.newItem.contactPostal,
                      pobox: $scope.newItem.contactPobox,
                      price_lvl: $scope.newItem.contactPriceLvl,
                      orgid: $cookies.get('orgid')
                  });
  
                  apiCalls.postData(url, data, function(response){
                      console.log(response);
  
                      // Toast
                      if(response.status == 201){
                          $mdToast.show(
                              $mdToast.simple()
                                  .textContent('Záznam bol vytvorený.')
                                  .position('bottom right')
                                  .action('Skryť')
                                  .highlightAction(true)
                                  .highlightClass('md-warn')
                          );
  
                          $mdDialog.cancel();   
                      }
                  });
              }
  </code></pre>