material icon indicating copy to clipboard operation
material copied to clipboard

0.11.1: dialog created from directive has 2 <md-dialog> DOM elements

Open GuyShaanan opened this issue 11 years ago • 1 comments

See codepen: http://codepen.io/anon/pen/OybKbr

I'm using $mdDialog.show({template: ''}), and 'myDir' is a directive with template="<md-dialog>...</md-dialog>"

What actually being created on the DOM is TWO <md-dialog> objects.

<div class="md-dialog-container ng-scope" style="top: 0px; height: 93px;">
 <md-dialog class="md-default-theme md-content-overflow md-transition-in" role="dialog" tabindex="-1" aria-describedby="dialog_0">
  <md-dialog aria-label="test" class="md-default-theme md-content-overflow" role="dialog" tabindex="-1" aria-describedby="dialog_0">
   <md-toolbar class="md-default-theme">
    <div class="md-toolbar-tools"><h2>Mango (Fruit)</h2>      <span class="flex"></span></div>
   </md-toolbar>
   <md-dialog-content id="dialog_0"><div ng-transclude=""><span class="ng-scope">CONTENT</span></div></md-dialog-content>
  </md-dialog>
 </md-dialog>
</div>

This is my code in a glance:

angular.module('MyApp', ['ngMaterial'])
.directive('myDir', MyDir)
.controller('AppCtrl', AppCtrl);

function MyDir() {
  return {
    restirct: 'EA',
    replace: true,
    transclude: true,
    template: '<md-dialog aria-label="test"><md-toolbar><div class="md-toolbar-tools"><h2>Mango (Fruit)</h2>      <span flex></span></div></md-toolbar><md-dialog-content><div ng-transclude></div></md-dialog-content></md-dialog>',
  }
}

function AppCtrl($scope, $mdDialog) {

  $scope.showAdvanced = function(ev) {
    $mdDialog.show({
      template: '<my-dir>CONTENT</my-dir>',
        parent: angular.element(document.body),
        targetEvent: ev,
        clickOutsideToClose: true
      });
  };
}

I believe this is caused by

transformTemplate: function(template) {
        return '<div class="md-dialog-container">' + validatedTemplate(template) + '</div>';

        /**
         * The specified template should contain a <md-dialog> wrapper element....
         */
        function validatedTemplate(template) {
          template || ""
          return /<\/md-dialog>/g.test(template) ? template : "<md-dialog>" + template + "</md-dialog>";
        }
      }

GuyShaanan avatar Sep 29 '15 08:09 GuyShaanan

+1

PezzerDev avatar Oct 07 '15 21:10 PezzerDev