@@ -156,6 +156,9 @@ function MdToastDirective($mdToast) {
156
156
* have an outer `md-toast` element.
157
157
* - `template` - `{string=}`: Same as templateUrl, except this is an actual
158
158
* template string.
159
+ * - `autoWrap` - `{boolean=}`: Whether or not to automatically wrap the template content with a
160
+ * `<div class="md-toast-content">` if one is not provided. Defaults to true. Can be disabled if you provide a
161
+ * custom toast directive.
159
162
* - `scope` - `{object=}`: the scope to link the template / controller to. If none is specified, it will create a new child scope.
160
163
* This scope will be destroyed when the toast is removed unless `preserveScope` is set to true.
161
164
* - `preserveScope` - `{boolean=}`: whether to preserve the scope when the element is removed. Default is false
@@ -277,7 +280,28 @@ function MdToastProvider($$interimElementProvider) {
277
280
onRemove : onRemove ,
278
281
position : 'bottom left' ,
279
282
themable : true ,
280
- hideDelay : 3000
283
+ hideDelay : 3000 ,
284
+ autoWrap : true ,
285
+ transformTemplate : function ( template , options ) {
286
+ var shouldAddWrapper = options . autoWrap && template && ! / m d - t o a s t - c o n t e n t / g. test ( template ) ;
287
+
288
+ if ( shouldAddWrapper ) {
289
+ // Root element of template will be <md-toast>. We need to wrap all of its content inside of
290
+ // of <div class="md-toast-content">. All templates provided here should be static, developer-controlled
291
+ // content (meaning we're not attempting to guard against XSS).
292
+ var parsedTemplate = angular . element ( template ) ;
293
+ var wrappedContent = '<div class="md-toast-content">' + parsedTemplate . html ( ) + '</div>' ;
294
+
295
+ parsedTemplate . empty ( ) . append ( wrappedContent ) ;
296
+
297
+ // Underlying interimElement expects a template string.
298
+ return parsedTemplate [ 0 ] . outerHTML ;
299
+ }
300
+
301
+ return shouldAddWrapper ?
302
+ '<div class="md-toast-content">' + template + '</div>' :
303
+ template || '' ;
304
+ }
281
305
} ;
282
306
283
307
function onShow ( scope , element , options ) {
0 commit comments