Was ich tun möchte, ist transcluden von Hand zu handhaben und den Inhalt zu ändern, bevor ich in das DOM einfügen:Wie ändert man den übertragenen Inhalt vor dem Kompilieren in die Direktive?
return {
restrict: 'E',
transclude: true,
template: '<HTML>',
replace: true,
link: function(scope, element, attrs, ngModelCtrl, $transclude) {
var caption = element.find('.caption');
$transclude(function(clone) {
console.log(clone);
clone.filter('li').addClass('ng-hide'); // this don't work
clone.addClass('ng-hide'); // same this one
clone.attr('ng-hide', 'true'); // same this one
$compile(clone)(scope.$new()).appendTo(caption);
caption.find('li').addClass('ng-hide'); // and this
});
}
}
In Angularjs Quelle ich dieses Beispiel gefunden:
var templateElement = angular.element('<p>{{total}}</p>'),
scope = ....;
var clonedElement = $compile(templateElement)(scope, function(clonedElement, scope) {
//attach the clone to DOM document at the right place
});
//now we have reference to the cloned DOM via `clonedElement`
aber Wenn ich clonedElement.appendTo(caption);
innerhalb Link-Funktion hinzufügen, fügen Sie nur einen Kommentar mit ng-Wiederholung innen.
Ich brauche das, weil ich alle Elemente in diesem Fall zu verstecken brauchen
<dropdown>
<li ng-repeat="item in items"><a>{{item.label}}</a></li>
</dropdown>
Ich brauche die Vorlage zu ändern, bevor kompilieren oder DOM nach ng-repeat erweitert wird. Vorher wäre es besser, weil ich in der Lage sein werde, Logik mit Hilfe der ng-hide-Direktive anstelle der ng-hide-Klasse hinzuzufügen.