anglejs 2の新機能で、@viewChildを使用する必要がありますが、''未定義の 'rotateLeft'プロパティを読み取れません。というエラーがスローされます。 親:Angularjs 2 @viewChildは動作していません
<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();
}}
子供:
@Component({
selector: 'pdfReader',
templateUrl: 'pdfReader.html'
})
export class PdfReader{
@Input() imageUrl : any;
rotateLeft(){
console.log('rotateLeft called');
this.rotationAngel -= 90;
}
}
'@ViewChild()'の使用方法に関するご質問はありません。これがあなたの質問の最も重要な部分だとは思わない? –
@GünterZö[email protected]( 'PdfReader')public pdfReader:PdfReader;また編集されました。 – sibi
'ngAfterViewInit()'の 'console.log(this.pdfReader);は何を出力しますか?あなたの質問のHTMLはコンポーネントテンプレートの一部ですか? '@Component()'デコレータとコンポーネントのクラス名をコードに追加してください。 –