我需要在加载时加载一个组件
<app-main id="tasks" [(ngModel)]="tasks"></app-main>还有js的电话
public tasks;
ngOnInit() {
    this.tasks.click();
}我试过document.getElementById("tasks").click()和ngAfterViewInit()
发布于 2017-08-08 09:35:40
要单击该元素,可以执行以下操作:
将html更改为:
<app-main id="tasks" #tasks></app-main>..。然后在组件类中:
import { Component, ElementRef, ViewChild, AfterViewInit } from '@angular/core';
//...
@ViewChild('tasks') tasks:ElementRef;
ngAfterViewInit () {
    // Fire the click event of tasks
    this.tasks.nativeElement.click();
}https://stackoverflow.com/questions/45564532
复制相似问题