New to angularjs 2, I need to use @viewChild but it throws error as 'Cannot read property 'rotateLeft' of undefined'. parent :
<div><pdfReader [imageUrl]="imgsource" *ngIf="holeDocument.ext == 'pdf'"></pdfReader></div>
.ts
import { Component ,ViewChild } from '@angular/core';
import {PdfReader} from "../../shared/pdfreader/pdfReader";
@Component({
selector: 'docView',
templateUrl: 'docView.html',
styleUrls : ["docView.less"]
})
export class DocViewComponent{
@ViewChild('PdfReader') public pdfReader: PdfReader;
constructor(){}
ngAfterViewInit(){
this.imageRotate();
}
imageRotate(){
this.pdfReader.rotateLeft();
}}
Child :
@Component({
selector: 'pdfReader',
templateUrl: 'pdfReader.html'
})
export class PdfReader{
@Input() imageUrl : any;
rotateLeft(){
console.log('rotateLeft called');
this.rotationAngel -= 90;
}
}