Can I use angular-selectize with require.js?

634 views Asked by At

angular-selectize.js needs selectize.js and angular.js to run. When I load those via require, no window.Selectize property gets exposed,which is needed by angular-selectize.js.

This is a snippet from selectize.js

if (typeof define === 'function' && define.amd) {
        define('selectize', ['jquery','sifter','microplugin'], factory);
    } else if (typeof exports === 'object') {
        module.exports = factory(require('jquery'), require('sifter'), require('microplugin'));
    } else {
        root.Selectize = factory(root.jQuery, root.Sifter, root.MicroPlugin);
    }

and a snippet from angular-selectize

 link: function(scope, element, attrs, modelCtrl) {

  Selectize.defaults.maxItems = null; //default to tag editor

  var selectize,
      config = angular.extend({}, Selectize.defaults, selectizeConfig, scope.config);
    ........


}

which needs the Selectize property to be exposed, and since its not available, because selectize goes into the

if (typeof define === 'function' && define.amd) 

, the global is not created and it errors out

So, whats the right way to use angular-selectize via require?

1

There are 1 answers

0
Paul Milburn On BEST ANSWER

I had same problem and fixed by adding Selectize to window.

(function (define) {
    'use strict';
    var dependencies = [
        'selectize',
        'angular',
        'ngMessages',
        'ngSelectize',
        'ngLoad'
    ];
    define(dependencies, function (Selectize) {

      window.Selectize = Selectize; 
      ...