Last active
October 2, 2019 04:30
-
-
Save christo8989/6a95a0ad97539128dce3899cd203a119 to your computer and use it in GitHub Desktop.
Custom binding handler that passes the element to the viewmodel. Typically, this should not be used but sometimes its easier to just get the element. In my case, some event happens and I want to focus on my input element.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ko.bindingHandlers.element = { | |
init: function (element, valueAccessor) { | |
var vmElement = valueAccessor(); | |
if (ko.isObservable(vmElement) === false) | |
throw Error("The binding handler needs an observable."); | |
vmElement(element); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment