答案 0 :(得分:6)
ngRepeat
有一个转换选项。$compile
编译transcluded元素,然后为指令的链接函数提供childTranscludeFn
函数作为第五个参数(或指令控制器中的$ transclude)if (directiveValue = directive.transclude) {
// some code
if (directiveValue == 'element') {
// some code
childTranscludeFn = compile($template, transcludeFn, terminalPriority,
replaceDirective && replaceDirective.name, {
// some comments
nonTlbTranscludeDirective: nonTlbTranscludeDirective
});
} else {
// some code
childTranscludeFn = compile($template, transcludeFn);
}
}
ngRepeat
内:var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
var NG_REMOVED = '$$NG_REMOVED';
var ngRepeatMinErr = minErr('ngRepeat');
return {
transclude: 'element',
priority: 1000,
terminal: true,
$$tlb: true,
link: function($scope, $element, $attr, ctrl, $transclude){
// some code
$scope.$watchCollection(rhs, function ngRepeatAction(collection){
// some code
for (index = 0, length = collectionKeys.length; index < length; index++) {
// some code
if (!block.scope) {
$transclude(childScope, function(clone) {
// some code
});
}
}
// some code
});
}
};