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

Commit

Permalink
fix(toast): toast template transform was not appending nodes.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
devversion authored and ThomasBurleson committed Apr 20, 2016
1 parent 93921f8 commit a8f43b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/toast/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,16 @@ function MdToastProvider($$interimElementProvider) {
var templateRoot = document.createElement('md-template');
templateRoot.innerHTML = template;

// Iterate through all root children, to detect possible md-toast directives.
for (var i = 0; i < templateRoot.children.length; i++) {
if (templateRoot.children[i].nodeName === 'MD-TOAST') {
var wrapper = angular.element('<div class="md-toast-content">');
wrapper.append(templateRoot.children[i].children);

// Wrap the children of the `md-toast` directive in jqLite, to be able to append multiple
// nodes with the same execution.
wrapper.append(angular.element(templateRoot.children[i].childNodes));

// Append the new wrapped element to the `md-toast` directive.
templateRoot.children[i].appendChild(wrapper[0]);
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/components/toast/toast.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ describe('$mdToast service', function() {
expect(toast.length).not.toBe(0);
}));

it('should correctly wrap the custom template', inject(function($timeout, $rootScope, $rootElement) {
var parent = angular.element('<div>');

setup({
template: '<md-toast>Message</md-toast>',
appendTo: parent
});

var toast = $rootElement.find('md-toast');
$timeout.flush();

expect(toast[0].querySelector('.md-toast-content').textContent).toBe('Message');
}));

it('should add position class to toast', inject(function($rootElement, $timeout) {
setup({
template: '<md-toast>',
Expand Down

0 comments on commit a8f43b8

Please sign in to comment.