CrossLead / angular-zendesk-widget

Angular wrapper for the Zendesk Web Widget
Apache License 2.0
18 stars 11 forks source link

Allow for account url to change after loading #3

Open bsouthga opened 8 years ago

bsouthga commented 8 years ago

Not sure how we can make this happen as the url is required when the script is injected, but there might be a way to move the script injection into a run statement (instead of a config)...

bsouthga commented 8 years ago

added the option for manually injecting the zendesk lib in this branch: https://github.com/CrossLead/angular-zendesk-widget/tree/dynamic-loading

bsouthga commented 8 years ago

Now, if the plugin is configured as such:

angular.module('myApp')
  .config(['ZendeskWidgetProvider', function(ZendeskWidgetProvider) {
    ZendeskWidgetProvider.init({
      manual: true
    });
  }]);

You can trigger the injection of the library at a later point like:

angular.module('myApp')
  .controller('main', ['$rootScope', 'ZendeskWidget', function($rootScope, ZendeskWidget) {    
    ZendeskWidget.settings({
      accountUrl: $rootScope.currentUser.accountUrl
    });
    // idempotent, so can call multiple times with no further effect
    ZendeskWidget.injectZendeskScript(); 
  }]);

To allow for injecting the script with an accountUrl that is retrieved from somewhere in the app unreachable via a .config() statement