Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose isCopySupported as a directive property #179

Closed
surajpoddar16 opened this issue May 2, 2019 · 7 comments
Closed

expose isCopySupported as a directive property #179

surajpoddar16 opened this issue May 2, 2019 · 7 comments

Comments

@surajpoddar16
Copy link
Contributor

Can we expose isCopySupported as a directive property so that, users can conditionally show copy button. Right now I have to get reference of isCopySupported method from the ClipboardService in each component I want to use the directive. I can create a PR if this seems legitimate.

@maxisam
Copy link
Owner

maxisam commented May 2, 2019

I think so. Go ahead.

@surajpoddar16
Copy link
Contributor Author

@maxisam seems like exposing isCopySupported will not solve this case. If NgIf is applied to the same element as the directive itself, it won't have access to the template reference variable for the same.

@surajpoddar16
Copy link
Contributor Author

Though a user can still wrap it inside another element on which the directive can be applied

@surajpoddar16
Copy link
Contributor Author

surajpoddar16 commented May 3, 2019

@maxisam I created a structural directive to support that conditionally renders target element based on isCopySupported flag. the code looks like this


import { ClipboardService } from './ngx-clipboard.service';

@Directive({
    // tslint:disable-next-line:directive-selector
    selector: '[ngxClipboardIfSupported]',
})
export class HdClipboardIfSupportedDirective implements OnInit {
    constructor(
        private _clipboardService: ClipboardService,
        private _viewContainerRef: ViewContainerRef,
        private _templateRef: TemplateRef<any>
    ) {}

    public ngOnInit() {
      if (this._clipboardService.isSupported) {
        this._viewContainerRef.createEmbeddedView(this._templateRef);
      }
    }
}

example implementation looks like this

<span
  *ngxClipboardIfSupported
  ngxClipboard
  cbContent="Foo bar"
  class="hevo-icon hevo-copy">
</span>

Should we provide a directive like this as well?

@maxisam
Copy link
Owner

maxisam commented May 3, 2019

yeah, I think we can. Make a pull request and I will take care of it. thx

@surajpoddar16
Copy link
Contributor Author

created a PR #182

@maxisam
Copy link
Owner

maxisam commented May 13, 2019

it is out in [email protected] Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants