Chciałbym uzyskać dostęp do zawartości ng-content, na początek wystarczy, aby uzyskać liczbę elementów treści, ale z większą awesomeness później.Jak uzyskać dostęp do zawartości Ng?
Na przykład:
@Component({
selector: 'my-container',
template: `
<div class="my-container">
<div class="my-container-nav"><a class="my-container-previous"></a></div>
<div class="my-container-body">
<div class="my-container-items">
<ng-content></ng-content>
</div>
</div>
<div class="my-container-nav"><a class="my-container-next"></a></div>
</div>
`
})
export class MyContainer implements AfterContentInit {
@ContentChildren(???) containerItems : QueryList<???>;
ngAfterContentInit() {
console.log('after content init: ' + this.containerItems.length);
}
}
Co mogę umieścić jako typ dla dzieci treści?
Mogą to być cokolwiek. Próbowałem ElementRef, ale to nie działało i zawsze dawało zero.
Przykład zastosowania:
<my-container>
<div>some content here</div>
<another-component [title]="'another component there'"></another-component>
<div>there's lots of content everywhere</div>
<span>no assumptions would be fair</span>
</my-container>
ja spodziewać się 'po zawartości INIT: 4'.
Czy elementy podrzędne Angular2, które kontrolujesz (tj. chcesz uzyskać dostęp do instancji składnika)? Lub po prostu HTML? – Sjoerd
Sjoerd, może być miksem. Spodziewam się losowego html, ale oczekuję również komponentów. A kiedy są komponentami, byłyby innego rodzaju. – Richard