link: function($scope, $element, $attrs, controller, $transclude) {
if (!$transclude) {
throw minErr('rgMultiTransclude')('orphan',
'Illegal use of rgMultiTransclude directive in the template! ' +
'No parent directive that requires a transclusion found. ' +
'Element: {0}',
startingTag($element));
}
var name = $attrs.rgMultiTransclude;
// 就是这里,把当前scope作为第一个参数传入到$transclude中
$transclude($scope, function(clone) {
var s = $scope;
var jqElm = clone.filter('[rg-multi-transclude-name=' + name + ']');
$element.empty();
$element.append(jqElm);
});
}
使用ng-transclude会令transclude的内容的作用域在外面,不能到达ng-repeat时的每一项。解决方法是编写自己的transclude,使$transclude使用ng-repeat的动态scope: