Reputation: 3
I need to load a component at loading
<app-main id="tasks" [(ngModel)]="tasks"></app-main>
And the call from js
public tasks;
ngOnInit() {
this.tasks.click();
}
I have tryed document.getElementById("tasks").click()
and ngAfterViewInit()
Upvotes: 0
Views: 2428
Reputation: 34673
To click the element, you can do the following:
Change your html to following:
<app-main id="tasks" #tasks></app-main>
... then in your component class:
import { Component, ElementRef, ViewChild, AfterViewInit } from '@angular/core';
//...
@ViewChild('tasks') tasks:ElementRef;
ngAfterViewInit () {
// Fire the click event of tasks
this.tasks.nativeElement.click();
}
Upvotes: 1