Reputation: 4422
I just found the v-el directive in Vue.js which is a great convenience for DOM-manipulation.
F.ex. I could mark an element with it:
<button v-el="getCustomerButton">Get customers</button>
and in the vue component use for example this.$$.getCustomerButton.focus()
to focus the button.
Is there some equivalent to v-el in angularjs?
Regards, Niels.
Upvotes: 1
Views: 277
Reputation: 3712
You can achieve that same result with the following directive:
angular.module('yourModuleNameHere').directive('vEl', [function() {
return {
restrict: 'A',
link: function(scope, element) {
// do whatever you want with element
// just element is the jqLite-wrapped object
// element[0] is the raw DOM node
}
};
}]);
Also note that element
is wrapped as a jqLite object, if you want the raw DOM node, you can get it with element[0]
.
In general, when you've applied a directive to an element, you can access that element in the link
function.
Upvotes: 1