2017-09-05 2 views
3

Ich habe ein Popup mit einem Eingabetyp, in dem ich die Autofokus-Option hinzufügen möchte. Ich habe eine Direktive für den Autofokus erstellt, die in Labels gut funktioniert, aber wenn ich dieselbe im Popup-Eingangstyp verwende, funktioniert sie nicht. Sogar ich habe den Fokus gesetzt - mir stimmt der Input zwar zu, aber selbst im Popup klappte es nicht. Kann mir jemand sagen, wie man den Autofokus im Popup benutzt?So verwenden Sie den Autofokus-Cursor im ionischen Popup

Richtlinie:

.directive('focusMe', function($timeout) { 
return { 
link: function(scope, element, attrs) { 

    $timeout(function() { 
    element[0].focus(); 
    }); 
} 
}; 
}); 

Popup:

function showPopup() { 
    $scope.data = {}; 
    var myPopup = $ionicPopup.show({ 
    template: '<input focus-Me type="text" ng-model="data.expensetype" limit-char limit="15">', 
    title: $translate.instant('{{"penterexpensetype_message" | translate}}'), 
    scope: $scope, 
    buttons: [ 
    { text: $translate.instant('{{"pcancel_message" | translate}}') }, 
     { 
     text: $translate.instant('{{"psave_message" | translate}}'), 
     type: 'button-positive', 
     onTap: function (e) { 
      if (!$scope.data.expensetype) { 
      //don't allow the user to close unless he enters producttype 
      e.preventDefault(); 

      } else { 
      addExpenseCategory(); 
      return $scope.data.expensetype; 
      } 
     } 
     }, 
    ] 
    }); 
    myPopup.then(function (res) { 
    $log.log('Tapped!', res); 
    }); 
} 

Antwort

1

Verwendung korrekte Richtlinie Name in Groß- und Klein

template: '<input focus-me type="text" ng-model="data.expensetype" limit-char limit="15">' 
Verwandte Themen