gpt4 book ai didi

angularjs - 打开时在 AngularUI 模式的输入字段中选择文本

转载 作者:行者123 更新时间:2023-12-02 03:37:55 24 4
gpt4 key购买 nike

我正在使用 AngularUI modal在我的应用程序中。模态包含预先填充了一些值的输入字段。要求:当模式打开时,应选择该输入字段中的文本。

我已经为选定的文本输入制定了指令,我得到的最远的是根据 this 在单击输入时选择所有文本。回答,这很好,但在打开模式时我需要该功能。

我在other thread看到过该模态实例已“打开” promise ,但在该 block 内我无法访问输入。

模态对话框:

var modalInstance = $modal.open({

templateUrl: 'app/main/templates/dialogs/share-dialog.tpl.html',
controller: function ModalCtrl($scope, $modalInstance, item) {

$scope.ok = function () {

$modalInstance.dismiss('cancel');
};

$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};

},
resolve: {
item: function () {
return item;
}
}
});

带有 select 指令的模板部分:

<input ng-model="shareLink" type="text" class="form-control" id="share" selected-text >

选定的文本指令:

var SelectedText = function () {
return {
restrict: 'A',
link: function(scope, element, attrs){
element.on('click', function () {
this.select();
});
}
};
};

return SelectedText;

最佳答案

我认为以下指令可以解决您的问题:

app.directive("selectImmediately", function($timeout) {
return {
restrict: "A",
link: function(scope, iElement) {
$timeout(function() { // Using timeout to let template to be appended to DOM prior to select action.
iElement[0].select()
});
}
}
});

用法:

<input ng-model="name" type="text" class="form-control" id="share" select-immediately >

plnkr 中的完整示例可见here .您可以在任何地方使用此指令。

关于angularjs - 打开时在 AngularUI 模式的输入字段中选择文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22093693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com