This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
feat($compile): support DOM nodes as template values #5508
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -512,6 +512,14 @@ describe('$compile', function() { | |
expect(element).toBe(attr.$$element); | ||
} | ||
})); | ||
|
||
directive('svgCircle', valueFn({ | ||
replace: true, | ||
template: jqLite('<svg><circle></circle></svg>').children() | ||
})); | ||
directive('domNodeTemplate', valueFn({ | ||
template: jqLite('<p>Hello!</p><p>world!</p>') | ||
})); | ||
})); | ||
|
||
|
||
|
@@ -675,6 +683,17 @@ describe('$compile', function() { | |
}).not.toThrow(); | ||
}); | ||
}); | ||
|
||
|
||
it('should accept DOM nodes as a template', inject(function($compile, $rootScope) { | ||
if (!(msie < 9)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only testing this on browsers which are not IE8, due to IE8 apparently not supporting SVG nodes... but I don't actually know if it would really fail on ie8 |
||
element = $compile('<svg><g svg-circle></g></svg>')($rootScope); | ||
expect(element.find('g').length).toBe(0); | ||
expect(element.find('circle').length).toBe(1); | ||
} | ||
element = $compile('<div dom-node-template></div>')($rootScope); | ||
expect(element.find('p').length).toBe(2); | ||
})); | ||
}); | ||
|
||
|
||
|
@@ -693,6 +712,17 @@ describe('$compile', function() { | |
expect($attrs.id).toBe('templateContent'); | ||
} | ||
})); | ||
directive('svgCircle', valueFn({ | ||
replace: true, | ||
template: function() { | ||
return jqLite('<svg><circle></circle></svg>').children(); | ||
} | ||
})); | ||
directive('domNodeTemplate', valueFn({ | ||
template: function() { | ||
return jqLite('<p>Hello!</p><p>world!</p>'); | ||
} | ||
})); | ||
})); | ||
|
||
|
||
|
@@ -701,6 +731,17 @@ describe('$compile', function() { | |
element = $compile('<div my-directive="some value">original content<div>')($rootScope); | ||
expect(element.text()).toEqual('template content'); | ||
})); | ||
|
||
|
||
it('should accept DOM nodes as a template', inject(function($compile, $rootScope) { | ||
if (!(msie < 9)) { | ||
element = $compile('<svg><g svg-circle></g></svg>')($rootScope); | ||
expect(element.find('g').length).toBe(0); | ||
expect(element.find('circle').length).toBe(1); | ||
} | ||
element = $compile('<div dom-node-template></div>')($rootScope); | ||
expect(element.find('p').length).toBe(2); | ||
})); | ||
}); | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this means that DOM templates won't be denormalized. that's not good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the individual nodes would end up denormalized later on though, no? Actually, I guess not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
denormalization is about taking all
{{ }}
bindings and turning them into whatever the the interpolation start and stop symbols are.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to happen so that reusable components can be built with the usual
{{ }}
bindings but then in the actual app we use whatever symbols the developer configured.