Skip to content

Commit

Permalink
fix: export copy (#484)
Browse files Browse the repository at this point in the history
* fix: export copy

* fix: change input to teaxarea to keep style
  • Loading branch information
ls32140 authored and aoilti committed Jan 3, 2020
1 parent 017a07b commit 6a3659a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
8 changes: 8 additions & 0 deletions demo/src/app/components/+copy/copy-section.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ <h3>4复制input输入的文字</h3>
<input #target2 />
</p>
</section>

<section class="mb-3">
<h3>5复制textarea输入的文字</h3>
<button thyButton="primary-square" (thyCopy)="copy($event)" [thyCopyContent]="target3">复制</button>
<p>
<textarea #target3></textarea>
</p>
</section>
1 change: 1 addition & 0 deletions demo/src/app/components/+copy/copy-section.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ThyCopyEvent } from 'ngx-tethys/directive/thy-copy.directive';
})
export class DemoCopySectionComponent {
constructor(private notifyService: ThyNotifyService) {}

copy(event: ThyCopyEvent) {
if (event.isSuccess) {
console.log('复制成功啦');
Expand Down
1 change: 1 addition & 0 deletions src/directive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './thy-row.directive';
export * from './thy-show';
export * from './thy-stop-propagation.directive';
export * from './thy-scroll.directive';
export * from './thy-copy.directive';
10 changes: 5 additions & 5 deletions src/directive/thy-copy.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export class ThyCopyDirective implements OnInit, OnDestroy {
}
@HostListener('click', ['$event'])
public onClick(event: Event) {
const input = this.document.createElement('input');
this.document.body.appendChild(input);
input.value = this.getContent(event);
input.select();
const textarea = this.document.createElement('textarea');
this.document.body.appendChild(textarea);
textarea.value = this.getContent(event);
textarea.select();
try {
document.execCommand('copy', false, null);
this.thyCopy.emit({ isSuccess: true, event });
Expand All @@ -68,7 +68,7 @@ export class ThyCopyDirective implements OnInit, OnDestroy {
this.thyCopy.emit({ isSuccess: false, event });
this.notifyService.error('复制失败');
} finally {
input.remove();
textarea.remove();
}
}

Expand Down

0 comments on commit 6a3659a

Please sign in to comment.