[英]Cannot use Renderer2 to change attribute of button referenced using ViewChild
[英]How to change Button text in ionic2 using Renderer2
我不知道如何使用 ElementRef 和 Renderer2 類更改 ionic2 中的按鈕文本。
這是我迄今為止嘗試過的。
@Component({
selector: 'component',
templateUrl: `<button #button type="submit" class="form-button" ion-button
[disabled]="!form.valid">Change this text</button>`;
})
export class component {
@ViewChild('button', {read: ElementRef})
private button : ElementRef;
constructor(private renderer: Renderer2){
}
ionViewDidLoad() {
this.renderer.setProperty(this.button.nativeElement, 'value', 'Cute alligator');
}
}
此setProperty
僅更改作為屬性的按鈕的值。 但我想更改按鈕文本,現在在按鈕內Change this text
。
請幫忙。 謝謝。
使用渲染器
this.renderer.setProperty(this.button.nativeElement, 'textContent', 'Your Text')
像這樣:
this.button.nativeElement.innerText = 'your text';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.