代码之家  ›  专栏  ›  技术社区  ›  user7383259

如何在ionic popup中使用自动对焦光标

  •  4
  • user7383259  · 技术社区  · 7 年前

    我有一个带有输入类型的弹出窗口,我想在其中添加自动对焦选项。我已经为自动对焦创建了一个指令,该指令在标签中运行良好,但当我在弹出式输入类型中使用相同的指令时,它不起作用。即使我在输入中设置了焦点me等于true,但即使在弹出窗口中也不起作用。谁能告诉我如何在弹出窗口中使用自动对焦?

    .directive('focusMe', function($timeout) {
    return {
    link: function(scope, element, attrs) {
    
      $timeout(function() {
        element[0].focus(); 
      });
    }
    };
    });
    

    弹出窗口:

    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);
      });
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Ragu    7 年前

    使用正确的大小写指令名

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