Angular在重新加载时不会调用nativeElement.click()

时间:2017-07-12 15:56:22

标签: angular typescript

我的角度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
        );

}

0 个答案:

没有答案