Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit a8f43b8

Browse files
devversionThomasBurleson
authored andcommitted
fix(toast): toast template transform was not appending nodes.
* Currently the toast template transform function was only appending *elements* (no nodes) and even the syntax for appendChild accepts only one node (not multiple) Fixes #8131. Closes #8132
1 parent 93921f8 commit a8f43b8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/components/toast/toast.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,16 @@ function MdToastProvider($$interimElementProvider) {
338338
var templateRoot = document.createElement('md-template');
339339
templateRoot.innerHTML = template;
340340

341+
// Iterate through all root children, to detect possible md-toast directives.
341342
for (var i = 0; i < templateRoot.children.length; i++) {
342343
if (templateRoot.children[i].nodeName === 'MD-TOAST') {
343344
var wrapper = angular.element('<div class="md-toast-content">');
344-
wrapper.append(templateRoot.children[i].children);
345+
346+
// Wrap the children of the `md-toast` directive in jqLite, to be able to append multiple
347+
// nodes with the same execution.
348+
wrapper.append(angular.element(templateRoot.children[i].childNodes));
349+
350+
// Append the new wrapped element to the `md-toast` directive.
345351
templateRoot.children[i].appendChild(wrapper[0]);
346352
}
347353
}

src/components/toast/toast.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ describe('$mdToast service', function() {
209209
expect(toast.length).not.toBe(0);
210210
}));
211211

212+
it('should correctly wrap the custom template', inject(function($timeout, $rootScope, $rootElement) {
213+
var parent = angular.element('<div>');
214+
215+
setup({
216+
template: '<md-toast>Message</md-toast>',
217+
appendTo: parent
218+
});
219+
220+
var toast = $rootElement.find('md-toast');
221+
$timeout.flush();
222+
223+
expect(toast[0].querySelector('.md-toast-content').textContent).toBe('Message');
224+
}));
225+
212226
it('should add position class to toast', inject(function($rootElement, $timeout) {
213227
setup({
214228
template: '<md-toast>',

0 commit comments

Comments
 (0)