javascript - Access a DOM element in Aurelia -
how go accessing dom element in aurelia? broad , general question, have feeling there 1 or 2 preferred ways this. have 2 current cases in aurelia now:
in template have form. want access form element in view-model, on vm candeactivate(), interrupt user navigating away half filled out form. scope in i'm trying access element can considered local.
in view-model want hide navigation on vm activate(). navigation resides in view-model/template pair scope may considered global.
as rob suggested, use ref
. example:
view
<form ref="myform"></form>
viewmodel
class viewmodel { candeactivate() { var form = this.myform; // stuffs } }
for more information on ref attribute, see here: http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/cheat-sheet/5
Comments
Post a Comment