0

I'm trying to display some XML as is in an $mdDialog using Angular Material. If I display it using a standard alert, I see the XML as I'd expect, but $mdDialog or Angular is stripping all of the tags from it.

Here's the code. Neither of the commented out lines make a difference as far as the XML is concerned.

             function displayFile(data, fieldName) {
                   var content = eval("data." + fieldName);
                   alert(content);

                   if (content) {
                       //content = $sanitize(content);
                       //content = $sanitize("<code>" + content + "</code>");
                   } else {
                       content = fieldName + " does not contain any content.";
                   };
                   var myAlert = $mdDialog.alert({
                       title: data.FILE_NAME,
                       content: content,
                       ok: 'Close'
                   });
                   $mdDialog
                       .show(myAlert)
                       .finally(function () {
                           myAlert = undefined;
                       });
               };

Any ideas?

Mike Feltman
  • 5,160
  • 1
  • 17
  • 38

1 Answers1

0

Putting up your own solution post in google group (so that it stays as a reference for all):

angular.module('myApp', ['ngMaterial'])
  .controller('mdDialogController', mdDialogController)

mdDialogController.$inject = ["$mdDialog"]

function mdDialogController($mdDialog) {
    vm = this;
    vm.show = function() {
      var xml = "\
          <header> \
              <detail>\
                  <item>item1</item>\
                  <item>item2</item>\
              </detail> \
           </header>"

      var myAlert = $mdDialog.alert({
        title: "Show me the XML",
        content: xml,
        ok: 'Close'
      });
      $mdDialog
        .show(myAlert)
        .finally(function() {
          myAlert = undefined;
        });
    };
};    
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="myApp">
<head>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/0.11.4/angular-material.min.css" />
  <title>mdDialog test</title>
</head>
<body>  
<div ng-controller="mdDialogController as dialog">
     <md-button ng-click="dialog.show()">
       Show Dialog
      </md-buton>
  </div> 
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-aria.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-resource.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-sanitize.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.11.4/angular-material.min.js"></script>
  </body>
Ani Menon
  • 27,209
  • 16
  • 105
  • 126
  • 1
    I was actually trying to display the XML as XML. I'm trying to display an incoming document as is. We since have switched to JSON and I was able to handle the display of raw JSON with the pre tag pretty easily. – Mike Feltman Apr 24 '16 at 11:43