【发布时间】:2019-10-16 02:25:23
【问题描述】:
我需要用户能够选择(使用鼠标或键盘)选定的标记值,并能够以某种方式复制文本。在以下示例 plunker 中,我需要用户能够复制文本“蓝色”/“红色”-
有什么建议吗?
【问题讨论】:
标签: tags angular-ui tagging ui-select textselection
我需要用户能够选择(使用鼠标或键盘)选定的标记值,并能够以某种方式复制文本。在以下示例 plunker 中,我需要用户能够复制文本“蓝色”/“红色”-
有什么建议吗?
【问题讨论】:
标签: tags angular-ui tagging ui-select textselection
你可以这样做:
创建一个指令,通过双击事件将项目的值复制到剪贴板:
app.directive('uiSelectCopy', [function(){
return {
restrict: 'A',
scope: {
$item: '=ngBind'
},
link: function ($scope, $elm) {
$elm.on('dblclick', function(){
let value = $scope.$item || this.innerText;
let input = angular.element(`<input value="${value}"/>`);
angular.element(document.body).append(input);
input[0].select();
document.execCommand('copy');
input.remove();
});
}
}
}])
然后将此指令添加到您的 ui-select-match 中:
<ui-select multiple tagging tagging-label="(custom 'new' label)" ng-model="multipleDemo.colors" theme="bootstrap"
sortable="true" ng-disabled="disabled" style="width: 300px;" title="Choose a color">
<ui-select-match placeholder="Select colors...">
<span ng-bind="$item" ui-select-copy></span>
</ui-select-match>
<ui-select-choices repeat="color in availableColors | filter:$select.search">
{{color}}
</ui-select-choices>
</ui-select>
如果需要,您还可以将事件更改为单击。
【讨论】: