2017-01-06 10 views
0

私はtypscriptでAngular2アプリケーションを持っています。私は、私は、ファイルがパスに存在しない場合に例外を生成したい、@Inputとしてそのファイルを受信した音声タグを、持っている:音声タグのハンドル404エラー

HTMLは次のとおりです。

<div> 
    <audio controls autoplay id="audio" (error)="audioError()"> 
     <!--source src="horse.ogg" type="audio/ogg"--> 
     <source [src]="fileToPlay" type="audio/mpeg"> 
     Your browser does not support the audio element. 
    </audio> 
</div> 

コンポーネントは次のとおりです。

export class PlayComponent implements OnChanges { 

    @Input() fileToPlay:string; 

    audioError(){ 
console.log('out of range'); 
} 

} 

onerrorを使用しようとしましたが動作しません。

答えて

1

onerrorの代わりに(error)を使用してください(パランシース付きのサラウンドイベント)。

<audio controls autoplay id="audio" (error)="audioError()"> 
    <!--source src="horse.ogg" type="audio/ogg"--> 
    <source [src]="fileToPlay" type="audio/mpeg"> 
    Your browser does not support the audio element. 
</audio> 
+0

まだ動作しません。私は私の質問を更新しました。 @Pankaj Parkar – Salman