angular-clipboard

WebJar for angular-clipboard

License

License

MIT
Categories

Categories

Angular User Interface Web Frameworks CLI
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

angular-clipboard
Last Version

Last Version

1.7.0
Release Date

Release Date

Type

Type

jar
Description

Description

angular-clipboard
WebJar for angular-clipboard
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/omichelsen/angular-clipboard

Download angular-clipboard

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/angular-clipboard/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>angular-clipboard</artifactId>
    <version>1.7.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/angular-clipboard/
implementation 'org.webjars.npm:angular-clipboard:1.7.0'
// https://jarcasting.com/artifacts/org.webjars.npm/angular-clipboard/
implementation ("org.webjars.npm:angular-clipboard:1.7.0")
'org.webjars.npm:angular-clipboard:jar:1.7.0'
<dependency org="org.webjars.npm" name="angular-clipboard" rev="1.7.0">
  <artifact name="angular-clipboard" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='angular-clipboard', version='1.7.0')
)
libraryDependencies += "org.webjars.npm" % "angular-clipboard" % "1.7.0"
[org.webjars.npm/angular-clipboard "1.7.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

angular-clipboard

Build Status Test Coverage npm bundle size (minified + gzip)

Copy text to clipboard by clicking a button without using Flash. This is using the Selection API and Clipboard API available in newer browsers.

Browser support: Chrome 43+, Firefox 41+, Opera 29+, IE10+, Safari 10+ and Mobile Safari 10+.

See the demo.

Install

$ npm install angular-clipboard --save

angular-clipboard has no other dependencies than Angular itself.

Usage

Require angular-clipboard as a dependency for your app:

angular.module('MyApp', ['angular-clipboard'])
    .controller('MyController', ['$scope', function ($scope) {
        $scope.supported = false;

        $scope.textToCopy = 'I can copy by clicking!';

        $scope.success = function () {
            console.log('Copied!');
        };

        $scope.fail = function (err) {
            console.error('Error!', err);
        };
    }]);

Copy text from an input field by clicking a button:

<input type="text" ng-model="textToCopy">
<button clipboard supported="supported" text="textToCopy" on-copied="success()" on-error="fail(err)">Copy</button>

You can supply a method to be called for the on-copied and on-error event. The on-error function will be called with the error object as argument err.

The optional supported property can be used to detect browser support for the clipboard feature.

Use as service

You can also invoke the copy to clipboard action directly by injecting the clipboard service. Just remember it has to be in a click event, as clipboard access requires user action.

angular.module('MyApp', ['angular-clipboard'])
    .controller('MyController', ['$scope', 'clipboard', function ($scope, clipboard) {
        if (!clipboard.supported) {
            console.log('Sorry, copy to clipboard is not supported');
        }

        $scope.clickHandler = function () {
            clipboard.copyText('Copy this text');
        };
    }]);

Use with a module loader

If you are using a module loader, you can import the module name when requiring it in angular. Works with any AMD/UMD/CommonJS module loader.

import clipboardModule from 'angular-clipboard';

angular.module('mymodule', [clipboardModule.name]);

Versions

Version
1.7.0
1.6.2
1.5.0
1.4.2