3つのカスタムボタンのセットを備えたコンポーネントがあり、これらのボタンをサウンドレコーダーのコントロールとして使用したいと考えています。私は最初のフェーズで立ち往生しました。そこで、ボタンに表示されているシンボルをその機能に従って変更したいのです。私はxlink:href属性(私はsvgを使用)を変更することでこれを達成しようとしましたが、彼はコンソールでこれを手に入れましたEXCEPTION: Error in ./RecordComponent class RecordComponent - inline template:5:45 caused by: this.roundButtonOne.getAttribute is not a function
。なぜ、どのように私はAngular2のアプローチでこれを実装することができますか?ここでは、コードは次のようになります。角2の変更属性
import {Component, ViewChild} from '@angular/core';
@Component({
selector: 'app-record',
template: `
<svg class='roundButtonOne icon'>
<use #roundButtonOne xlink:href='#mic'(click)='onRecord()'/>
</svg>
<svg class='roundButtonTwo icon'>
<use #roundButtonTwo xlink:href='#live' />
</svg>
<svg class='roundButtonThree icon'>
<use #roundButtonThree xlink:href='#upload' />
</svg>
</div>
`
})
export class RecordComponent {
private recording: boolean = false;
@ViewChild('roundButtonOne') roundButtonOne: HTMLElement;
@ViewChild('roundButtonTwo') roundButtonTwo: HTMLElement;
@ViewChild('roundButtonThree') roundButtonThree: HTMLElement;
onRecord(){
this.recording = true;
switch(this.roundButtonOne.getAttribute('xlink:href')){
case '#mic':
this.record();
break;
}
}
record(){
this.roundButtonOne.setAttribute('xlink:href','#mic-small');
this.roundButtonTwo.setAttribute('xlink:href', '#pause');
this.roundButtonThree.setAttribute('xlink:href', '#stop');
}
}
それは働いた、ありがとうございました! –