How to add linebreak to textContent in $mdDialog

In order to accomplish this task you will need to install angular-sanitize.js. This js can be downloaded from here. After downloading, link that to your project after loading angularJS.

<head>
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/angular/angular.min.js"></script>
    <script src="~/Scripts/sanitize/sangular-sanitize.js"></script>
</head>

Since this is a provider you need to be instantiated and wired in the module together for the app to work. Following JS shows how to inject the provider.

<script type="text/javascript">
    var app = angular.module('MyApp', ['ngMaterial','ngMessages', 'ngSanitize']);
    var baseUrl = 'http://localhost:54037/Home/'
</script>

After that you can use .htmlContent in the code as follows

$mdDialog.show(
$mdDialog.alert()
    .clickOutsideToClose(true)
    .title('Your Tile')
    .htmlContent("<h1>html</h1><h4>works</h4>")
    .ok('Okay!')
);

Use .htmlContent().

$mdDialogPreset#textContent(string) - Sets the confirm message. $mdDialogPreset#htmlContent(string) - Sets the confirm message as HTML. Requires ngSanitize module to be loaded. HTML is not run through Angular's compiler.

Documentation

Tags:

Angularjs