Question Details

No question body available.

Tags

angular

Answers (2)

January 21, 2026 Score: 0 Rep: 59,003 Quality: Medium Completeness: 60%

how check Angular?

first execute the whole function, then check.

This is the reason not work your foo() function

Your bar function works because the setTimeout makes Angular check again NOT because "angular is late". See that you can not use the argument milliseconds. but you can use also simply:

//see that not use async or Promise or ... bar() { this.data.set({ id: "12345678" }) setTimeout(()=>{ let docEl = document.getElementById("12345678"); // now finds it console.log(docEL) }) }

See that, even you use "effect" you need "again redraw"

constructor() { effect(() => { const data = this.data(); setTimeout(() => { let docEl = document.getElementById('node_' + this.data().id); // now finds console.log(this.data().id, docEl); }); }); }

You can use also inject ChangeDetectorRef

cdRef=inject(ChangeDetectorRef) bar() { this.data.set({ id: this.data().id + 1, }); this.cdRef.detectChanges(); //
January 21, 2026 Score: 0 Rep: 66,514 Quality: Medium Completeness: 80%

Since you are using signals, you should reactively trigger using afterRenderEffect which run after the DOM renders. My understanding is hazy but it works similar to ngAfterViewInit where it runs after the DOM renders.

Angular - afterRenderEffect Docs

@Component({
  selector: 'app-root',
  template: `
    
node{{data().id}}
foo bar `, }) export class App { data = signal({ id: 12345678 });

constructor() { afterRenderEffect(() => { let docEl = document.getElementById('node
' + this.data().id); console.log(docEl); }); }

foo() { this.data.set({ id: this.data().id + 1, }); }

async bar() { this.data.set({ id: this.data().id + 1, }); } }

Stackblitz Demo