javascript - Event on one element to trigger event on another -
i'll use specific example apply any event on 1 element triggering any event on another. suppose want focus <input>
when click <span>
. can using directive like:
<div ng-controller="ctrl"> <span ng-focus-other>focus</span><input> <div> app.directive("ngfocusother", function () { return function (scope, element) { element.bind("click", function () { this.nextsibling.focus(); }); }; });
however not seem angular. not work there changes dom (e.g. if <input>
moved before <span>
). nice if same code work on multiple groups of <span>
-<input>
combinations perhaps each different dom layout.
what angular way of using 1 event trigger event on element?
why not have clicking span set boolean called "inputfocused" true , let input pay attention scope variable. i.e.
<span ng-click="inputfocused = true">focus</span> <input ng-focus="inputfocused" value="give me focus">
Comments
Post a Comment