我的角度4应用程序中有一种奇怪的行为。
当我重新加载应用时,nativeElement.click不会被调用。但是,如果我改变路线,然后再次回到受影响的路线,它就像一个魅力..任何帮助或暗示赞赏!
见下面的代码:
documents.component.ts
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { DocumentService } from '../shared/services/document.service';
import { ActivatedRoute, Params, Router, RouterState } from '@angular/router';
import { DialogService } from '../shared/services/dialog.service';
@Component({
moduleId: module.id,
selector: 'documents',
templateUrl: 'documents.component.html',
styleUrls: ['documents.component.css']
})
export class DocumentsComponent implements OnInit,AfterViewInit {
private cols: number;
@ViewChild('cameraUpload') el:ElementRef;
@ViewChild('canvas') canvas:ElementRef;
constructor(private documents: DocumentService,
private elemRef: ElementRef,
private dialogService: DialogService,
private route: ActivatedRoute,
private router: Router) {
}
ngAfterViewInit(): void {
this.el.nativeElement.click(); // <--- This doesn't always get invoked!
}
ngOnInit(): void {
this.cols = Math.ceil(
this.elemRef.nativeElement.querySelector("div").clientWidth / 220
);
}