Search code examples
ionic-frameworkattributesionic4

How to get attribute value in <a> element?


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'>Text</a>

I know that in jquery I can use the: $('a').attr ('data-set');

And to change your content: $('a').attr ('data-set', '01');

But in Ionic4 i am not getting it, already researched and can not exactly that.

Can anyone help me?


Solution

  • SOLVED:

    I did it this way:

    <ion-input #myInput data-set="01"></ion-input>
    
    @ViewChild ('myInput', { read: ElementRef }) myInput: ElementRef;
    
    
    ngAfterContentInit() {
       console.log(this.myInput.nativeElement.dataset.dta1); 
    }