|
1 | 1 | # angular-zendesk-widget
|
2 |
| -Angular wrapper for the Zendesk Web Widget |
| 2 | +Angular wrapper for the [Zendesk Web Widget](https://support.zendesk.com/hc/en-us/articles/203908456-Using-Web-Widget-to-embed-customer-service-in-your-website) |
| 3 | + |
| 4 | +## Installation |
| 5 | +Via bower: |
| 6 | +```bash |
| 7 | +$ bower install angular-zendesk-widget |
| 8 | +``` |
| 9 | +Or grab the [latest release](https://github.com/CrossLead/angular-zendesk-widget/releases) and add the JavaScript directly: |
| 10 | +```html |
| 11 | +<!-- Minified --> |
| 12 | +<script type="text/javascript" src="dist/angular-zendesk-widget.min.js"></script> |
| 13 | +<!-- Unminified --> |
| 14 | +<script type="text/javascript" src="dist/angular-zendesk-widget.js"></script> |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage |
| 18 | +First, you'll need to setup the widget during the Angular configuration phase using the `ZendeskWidgetProvider`: |
| 19 | +```js |
| 20 | +angular.module('myApp', ['zendeskWidget']) |
| 21 | + .config(['ZendeskWidgetProvider', function(ZendeskWidgetProvider) { |
| 22 | + ZendeskWidgetProvider.init({ |
| 23 | + accountUrl: 'crosslead.zendesk.com' |
| 24 | + // See below for more settings |
| 25 | + }); |
| 26 | + }]); |
| 27 | +``` |
| 28 | +Then simply inject the `ZendeskWidget` service and use it to call any of the [Web Widget API methods](https://developer.zendesk.com/embeddables/docs/widget/api): |
| 29 | + |
| 30 | +JavaScript: |
| 31 | +```js |
| 32 | +angular.module('myApp') |
| 33 | + .controller('MyAppCtrl', ['ZendeskWidget', function(ZendeskWidget) { |
| 34 | + $scope.doCustomWidgetStuff = function() { |
| 35 | + ZendeskWidget.identify({ |
| 36 | + name: $scope.currentUser.displayName, |
| 37 | + email: $scope.currentUser.email, |
| 38 | + externalId: $scope.currentUser._id, |
| 39 | + }); |
| 40 | + ZendeskWidget.activate({hideOnClose:true}); |
| 41 | + }; |
| 42 | + }]); |
| 43 | +``` |
| 44 | +HTML: |
| 45 | +```html |
| 46 | +<div ng-app="myApp" ng-controller="MyAppCtrl"> |
| 47 | + <a ng-click="doCustomWidgetStuff()">Click me</a> |
| 48 | +</div> |
| 49 | +``` |
| 50 | +# Settings |
| 51 | +The following are all the settings that you can pass to `ZendeskWidgetProvider.init()`: |
| 52 | +```js |
| 53 | +ZendeskWidgetProvider.init({ |
| 54 | + // Your Zendesk account URL. Required |
| 55 | + accountUrl: 'crosslead.zendesk.com', |
| 56 | + // Callback to execute after the Zendesk Widget initializes |
| 57 | + // but before the page finishes loading. Probably the best |
| 58 | + // example from the Zendesk docs is hiding the widget initially (see |
| 59 | + // https://developer.zendesk.com/embeddables/docs/widget/api#ze.hide). |
| 60 | + // Note you do **not** need to wrap your calls in an extra `ze()` closure |
| 61 | + beforePageLoad: function(zE) { |
| 62 | + zE.hide(); |
| 63 | + } |
| 64 | +}); |
| 65 | +``` |
0 commit comments