我没有得到如何使用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.button.nativeElement.innerText = 'your text';
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句