Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 Get data from HTML data- attribute to component

I have issue with getting data from HTML data attr to component.

In Template I have:

<button [attr.data-direction]="next" type="text" (click)="nextNotes()" [disabled]="checkPage(paginator)"> > </button>

And how can I call this data attr in class method after click? There is some ng workflow for that or purejs?

console.log(data)
like image 880
Uland Nimblehoof Avatar asked Sep 12 '26 05:09

Uland Nimblehoof


1 Answers

Not sure if I am 100 % capish here, but if you just want the value from data-directive, then you could pass the button as a local variable to nextNotes() and retrieve the value from there using getAttribute

Template:

<button #btn data-direction="next" type="text" (click)="nextNotes(btn)" [disabled]="checkPage(paginator)"></button>

Class method:

nextNotes(val) {
  console.log(val.getAttribute('data-direction'))
}
like image 159
unitario Avatar answered Sep 13 '26 18:09

unitario



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!