In the Creating Container Components...with Angular talk at the ng-conf 2015. The reference some transclusion and custom code to 'match' and 'insert' user content into specific/deliberate elements/tags of the directive's template. ie. <nav t-id="menu"></nav><main t-id="body"></main>
Here is the link to the talk at the spot where they show the code being used. Got most of it working except the expression using the find()
method. Here is the code:
First the statement/expression in question var target = elem.find('[t-id="'+tId+'"]');
and then full link code below.
.directive('my-container-directive', function() {
return {
transclude: true,
template: `...`,
link: function(scope, elem, ctrl, transclude) {
transclude(clone) {
angular.forEach(clone, function(cloneEl){
// get desired target id
tId = cloneEl.attributes["t-to"].value;
// find the target with that ID
var target = elem.find('[t-id="'+tId+'"]');
// append an el to target
target.append(cloneEl);
})
}
}
};
});
Question 1: The use of the find() does not make sense to me and can not get it to work. What is with the [] syntax; It does not seem to follow either jqLites(angular's api docs) or jQuery docs. Angular for example says the find() 'Limited to look up by tag name'.
Full code is in thisplunk
Question 1.1: How would you find a tag with a certain attribute name and value name? ie. t-id="menu"?