diff options
| author | Igor Minar | 2012-05-04 01:24:46 -0700 |
|---|---|---|
| committer | Igor Minar | 2012-05-04 13:01:55 -0700 |
| commit | 9c0418cf1abd609bf0ffbe71fbdfa75905cf8e0f (patch) | |
| tree | 4f1582b46d8e17c1b72962cfac93be54d714b556 /src/ng/compile.js | |
| parent | 1564b82b49d996503fe782a1c1baa0a08608cf6a (diff) | |
| download | angular.js-9c0418cf1abd609bf0ffbe71fbdfa75905cf8e0f.tar.bz2 | |
fix($compile): ignore ws when checking if template has single root
Also add the same error checking for sync templates.
Closes #910
Diffstat (limited to 'src/ng/compile.js')
| -rw-r--r-- | src/ng/compile.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js index 4a18b1a7..6a6ffc3c 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -145,7 +145,7 @@ function $CompileProvider($provide) { Suffix = 'Directive', COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/, CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/, - HAS_ROOT_ELEMENT = /^\<[\s\S]*\>$/; + MULTI_ROOT_TEMPLATE_ERROR = 'Template must have exactly one root element. was: '; this.directive = function registerDirective(name, directiveFactory) { @@ -587,8 +587,14 @@ function $CompileProvider($provide) { assertNoDuplicate('template', templateDirective, directive, $compileNode); templateDirective = directive; - compileNode = jqLite(directiveValue)[0]; + $template = jqLite('<div>' + trim(directiveValue) + '</div>').contents(); + compileNode = $template[0]; + if (directive.replace) { + if ($template.length != 1 || compileNode.nodeType !== 1) { + throw new Error(MULTI_ROOT_TEMPLATE_ERROR + directiveValue); + } + replaceWith($rootElement, $compileNode, compileNode); var newTemplateAttrs = {$attr: {}}; @@ -840,15 +846,17 @@ function $CompileProvider($provide) { $http.get(origAsyncDirective.templateUrl, {cache: $templateCache}). success(function(content) { - if (replace && !content.match(HAS_ROOT_ELEMENT)) { - throw Error('Template must have exactly one root element: ' + content); - } - - var compileNode, tempTemplateAttrs; + var compileNode, tempTemplateAttrs, $template; if (replace) { + $template = jqLite('<div>' + trim(content) + '</div>').contents(); + compileNode = $template[0]; + + if ($template.length != 1 || compileNode.nodeType !== 1) { + throw new Error(MULTI_ROOT_TEMPLATE_ERROR + content); + } + tempTemplateAttrs = {$attr: {}}; - compileNode = jqLite(content)[0]; replaceWith($rootElement, $compileNode, compileNode); collectDirectives(compileNode, directives, tempTemplateAttrs); mergeTemplateAttributes(tAttrs, tempTemplateAttrs); |
