如何使用Renderer2更改ionic2中的按钮文本

Maantu Das

我没有得到如何使用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现在的按钮文本

请帮忙。谢谢。

Vivek Doshi

像这样:

this.button.nativeElement.innerText = 'your text';

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章