[SOLVED] Focus on input hidden input that appears every time button presed


I have an input that appears in the footer whenever y press the add button, and i want to focus the input when it appears, every time it does, i have managed to focus it if it loads with the page , but i need to be shown and focus just when i press the button

Here is the example:



I have modified previous example and get it working!
Later i will try it in my project and post here the results


It worked using this code:

.factory('focus', function($timeout, $window) {
    return function(id) {
      // timeout makes sure that it is invoked after any other event has been triggered.
      // e.g. click events that need to run before the focus or
      // inputs elements that are in a disabled state but are enabled when those events
      // are triggered.
      $timeout(function() {
        var element = $window.document.getElementById(id);
  }).directive('eventFocus', function(focus) {
    return function(scope, elem, attr) {
      elem.on(attr.eventFocus, function() {

      // Removes bound events in the element itself
      // when the scope is destroyed
      scope.$on('$destroy', function() {

Then inject focus on the controller

.controller('TestController', function($scope,$ionicScrollDelegate,focus) 

and call


that focus this input

 <input id="email" type="text" placeholder="text" ng-model="email">