diff --git a/src/components/toast/toast.js b/src/components/toast/toast.js index 22ddbb6bdb5..d6d69d716fc 100644 --- a/src/components/toast/toast.js +++ b/src/components/toast/toast.js @@ -289,18 +289,22 @@ function MdToastProvider($$interimElementProvider) { // Root element of template will be . We need to wrap all of its content inside of // of
. All templates provided here should be static, developer-controlled // content (meaning we're not attempting to guard against XSS). - var parsedTemplate = angular.element(template); - var wrappedContent = '
' + parsedTemplate.html() + '
'; + var templateRoot = document.createElement('md-template'); + templateRoot.innerHTML = template; + + for (var i = 0; i < templateRoot.children.length; i++) { + if (templateRoot.children[i].nodeName === 'MD-TOAST') { + var wrapper = angular.element('
'); + wrapper.append(templateRoot.children[i].children); + templateRoot.children[i].appendChild(wrapper[0]); + } + } - parsedTemplate.empty().append(wrappedContent); - // Underlying interimElement expects a template string. - return parsedTemplate[0].outerHTML; + return templateRoot.outerHTML; } - return shouldAddWrapper ? - '
' + template + '
' : - template || ''; + return template || ''; } }; @@ -310,6 +314,8 @@ function MdToastProvider($$interimElementProvider) { var isSmScreen = !$mdMedia('gt-sm'); element = $mdUtil.extractElementByName(element, 'md-toast', true); + options.element = element; + options.onSwipe = function(ev, gesture) { //Add the relevant swipe class to the element so it can animate correctly var swipe = ev.type.replace('$md.',''); diff --git a/src/components/toast/toast.spec.js b/src/components/toast/toast.spec.js index aff0c6f1a91..69bed050c4a 100644 --- a/src/components/toast/toast.spec.js +++ b/src/components/toast/toast.spec.js @@ -157,6 +157,19 @@ describe('$mdToast service', function() { expect(toast.text().trim()).toBe('hello, 1'); })); + it('should not throw an error if template starts with comment', inject(function($timeout, $rootScope, $rootElement) { + var parent = angular.element('
'); + setup({ + template: '{{1}}234', + appendTo: parent + }); + + var toast = $rootElement.find('md-toast'); + $timeout.flush(); + + expect(toast.length).not.toBe(0); + })); + it('should add position class to toast', inject(function($rootElement, $timeout) { setup({ template: '',