As pointed out in the comments, you probably don't want to use JQuery on Angular DOM elements if you have a choice. It will lead to endless confusion.
You can, however, access a component's DOM children using elementRef.nativeElement
. The lifecycle hook where you want to run that in the case of *ngFor
(or other structural directives) is AfterViewChecked
. At that point, you know that the component has finished binding and rendering its content.
Combined, here's a cheap little example just coloring all dynamically generated divs of a component:
import {AfterViewChecked, Component, ElementRef} from '@angular/core';
@Component({
selector: 'app-root',
template: `
<div *ngFor="let entry of entries">
{{entry}}
</div>
`
})
export class AppComponent implements AfterViewChecked {
constructor(private elementRef: ElementRef) {}
entries = ['a', 'b', 'c'];
ngAfterViewChecked(): void {
const divs = this.elementRef.nativeElement.querySelectorAll('div');
divs.forEach(div => div.style.background = 'red');
}
}