Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Button text in ionic2 using Renderer2

I am not getting how to change the button text in ionic2 using ElementRef & Renderer2 class.

Here is what I have tried so far.

@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');
   }
}

This setProperty only change the value of the button which is as attribute. But I want to change the button text which is now Change this text inside button.

Please help. Thanks.

like image 242
Maantu Das Avatar asked Oct 21 '25 04:10

Maantu Das


1 Answers

Using Renderer

this.renderer.setProperty(this.button.nativeElement, 'textContent', 'Your Text') 
like image 157
Nishant Singh Avatar answered Oct 23 '25 20:10

Nishant Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!