How to take value of element attribute with Angular IONIC4

Asked

Viewed 94 times

0

How can I take the value of the data set attribute or change it in the link with the following structure:

<a href='#' data-set='22'>Texto</a>

I know that in jquery I can use:

$('a').Attr('conjunto de dados');

And to change its content:

$('a').Attr('conjunto de dados', '01');

But in Ionic4 I’m not succeeding, I’ve already researched and I can’t exactly that.

Can someone help me?

  • But you’re using Ionic with what? Pure Javascript, Angular, React, Vue??

  • I’m using with Angular

  • And what you know of Angular?

  • I’m starting in ionic4 with angular. But I already know enough things. You can help?

  • So Jose, you can take the value of the attribute href or any other value of any other attribute with normal pure Javascript or with Angular even with a @Viewchild for example.

  • Thank you very much for contributing. In this case how can I take or change the href attribute with the use of @Viewchild for example?

Show 1 more comment

1 answer

2


I got it like this:

<ion-input #myInput data-set="01"></ion-input>

@ViewChild ('myInput', { read: ElementRef }) myInput: ElementRef;


ngAfterContentInit() {
   console.log(this.myInput.nativeElement.dataset.dta1); 
}

Working properly with IONIC4 and Angular4.

Thank you so much for your contribution @Leandrade

  • No need to write solved, just click on the check next to the answer. + 1 for using dataset

  • Thank you Guilerme! Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.