Javascript 如何在弹出窗口中使用自动对焦光标
我有一个带有输入类型的弹出窗口,我想在其中添加自动对焦选项。我已经为自动对焦创建了一个指令,该指令在标签中运行良好,但当我在弹出式输入类型中使用相同的指令时,它就不起作用了。即使我在输入中设置了“焦点我等于真”,但在弹出窗口中也不起作用。有人能告诉我如何在弹出窗口中使用自动对焦吗 指令:Javascript 如何在弹出窗口中使用自动对焦光标,javascript,ionic-framework,angularjs-directive,popup,Javascript,Ionic Framework,Angularjs Directive,Popup,我有一个带有输入类型的弹出窗口,我想在其中添加自动对焦选项。我已经为自动对焦创建了一个指令,该指令在标签中运行良好,但当我在弹出式输入类型中使用相同的指令时,它就不起作用了。即使我在输入中设置了“焦点我等于真”,但在弹出窗口中也不起作用。有人能告诉我如何在弹出窗口中使用自动对焦吗 指令: .directive('focusMe', function($timeout) { return { link: function(scope, element, attrs) { $timeout(f
.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);
});
}
函数showPopup(){
$scope.data={};
var myPopup=$ionicPopup.show({
模板:“”,
标题:$translate.instant('{“penterexpensetype_message”| translate}}'),
范围:$scope,
按钮:[
{text:$translate.instant({{“pcancel_message”{124; translate}}')},
{
text:$translate.instant('{“psave_message”| translate}}'),
键入:'按钮正',
onTap:功能(e){
if(!$scope.data.expensetype){
//除非用户输入producttype,否则不允许用户关闭
e、 预防默认值();
}否则{
AddExpenseContegory();
返回$scope.data.expensetype;
}
}
},
]
});
myPopup.then(函数(res){
$log.log('Tapped!',res);
});
}
使用正确的大小写指令名
template: '<input focus-me type="text" ng-model="data.expensetype" limit-char limit="15">'
模板:“”