Angularjs “角度材质”对话框:在第一项上设置焦点
我在材质设计中使用Angular 1.5.x,我有一个自定义对话框,我想在显示对话框时选择第一个输入字段 我该怎么做 我为这个问题提供了一个活生生的例子: 这是代码Angularjs “角度材质”对话框:在第一项上设置焦点,angularjs,dialog,focus,angular-material,Angularjs,Dialog,Focus,Angular Material,我在材质设计中使用Angular 1.5.x,我有一个自定义对话框,我想在显示对话框时选择第一个输入字段 我该怎么做 我为这个问题提供了一个活生生的例子: 这是代码 $mdDialog.show({ parent: parentEl, targetEvent: $event, // determines source location of the dialog template: ' <md-dialog>' +
$mdDialog.show({
parent: parentEl,
targetEvent: $event, // determines source location of the dialog
template:
' <md-dialog>' +
' <md-content>Hello {{ username }}!</md-content>' +
' <div class="md-actions">' +
' <form>' +
' <div>Given names: <input /></div>' +
' <div>Surname: <input /></div>' +
' <div>Address: <input /></div>' +
' <div>Building: <input /></div>' +
' <div>Level: <input /></div>' +
' <div>Street: <input /></div>' +
' <div>Suburb: <input /></div>' +
' <div>Postcode: <input /></div>' +
' <div>Country: <input /></div>' +
' <div>State: <input /></div>' +
' <div>ABN: <input /></div>' +
' <div>' +
' <md-button ng-click="closeDialog()">' +
' Close Greeting' +
' </md-button>' +
' </div>' +
' </form>' +
' </div>' +
' </md-dialog>',
onComplete: onCompleteAnimation,
locals: {
name: $scope.username
},
controller: DialogController
});
$mdDialog.show({
家长:家长,
targetEvent:$event,//确定对话框的源位置
模板:
' ' +
“你好{{username}}!”+
' ' +
' ' +
'姓名:'+
‘姓’+
“地址:”+
“建筑:”+
“级别:”+
“街道:”+
“郊区:”+
'邮政编码:'+
“国家:”+
'国家:'+
“荷兰银行:”+
' ' +
' ' +
“亲密问候”+
' ' +
' ' +
' ' +
' ' +
' ',
onComplete:onCompleteAnimation,
当地人:{
名称:$scope.username
},
控制器:对话框控制器
});
在本例中,我希望该对话框以给定名称为焦点出现。在onCompleteAnimation函数中,查找第一个输入并聚焦
onComplete: function(s,e) {
$(e).find('input').first().focus()
},
locals: {
name: $scope.username
},
controller: DialogController
这不是md自动对焦的用途吗?因此,将其添加到需要关注的元素中