如何在离子弹出窗口中使用自动对焦光标
How to use autofocus cursor in ionic popup
我有一个带有输入类型的弹出窗口,我想在其中添加自动对焦选项。我已经为自动对焦创建了一个指令,它在标签中工作正常,但是当我在弹出输入类型中使用相同的指令时,它不起作用。即使我在输入中设置了 focus-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);
});
}
使用正确的大写和小写指令名称
template: '<input focus-me type="text" ng-model="data.expensetype" limit-char limit="15">'
我有一个带有输入类型的弹出窗口,我想在其中添加自动对焦选项。我已经为自动对焦创建了一个指令,它在标签中工作正常,但是当我在弹出输入类型中使用相同的指令时,它不起作用。即使我在输入中设置了 focus-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);
});
}
使用正确的大写和小写指令名称
template: '<input focus-me type="text" ng-model="data.expensetype" limit-char limit="15">'