[英]Angular2 Get data from HTML data- attribute to component
我在從HTML數據屬性到組件獲取數據時遇到問題。
在模板中,我有:
<button [attr.data-direction]="next" type="text" (click)="nextNotes()" [disabled]="checkPage(paginator)"> > </button>
單擊后如何在類方法中調用此數據屬性? 那或purejs有一些ng工作流程嗎?
console.log(data)
不知道我在這里是否100%願意接受,但是如果您只想從data-directive
獲取值,則可以將按鈕作為局部變量傳遞給nextNotes()
並使用getAttribute
從那里獲取值
模板:
<button #btn data-direction="next" type="text" (click)="nextNotes(btn)" [disabled]="checkPage(paginator)"></button>
類方法:
nextNotes(val) {
console.log(val.getAttribute('data-direction'))
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.