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

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -