我在从组件中获取HTML数据时遇到了问题。
在模板中,我有:
<button [attr.data-direction]="next" type="text" (click)="nextNotes()" [disabled]="checkPage(paginator)"> > </button>单击后如何在类方法中调用此数据属性?有一些ng工作流程可以解决这个问题吗?还是纯粹的?
console.log(data)发布于 2017-02-08 01:05:46
我不确定我在这里是不是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'))
}https://stackoverflow.com/questions/42093310
复制相似问题