kbanman / selectize-ng

Selectize directive for AngularJS with two-way bindings for both values and options
MIT License
19 stars 7 forks source link

Error: data is undefined in console #13

Open tonysepia opened 7 years ago

tonysepia commented 7 years ago

Hi guys,

I have noticed the following error in the console: Error: data is undefined

have traced it to the following bit of code in selectize-ng:

if (attrs.options) {
          scope.$parent.$watchCollection(attrs.options, setSelectizeOptions);
        }

I guess the expected behaviour here is that #watchCollection will only execute listener function (setSelectizeOptions) when there are new values.

However, I have added the following line into setSelectizeOptions function and confirmed that sometimes it is being called even without the newOptions argument:

function setSelectizeOptions(newOptions) {
            if(newOptions==null){
                console.log("newOptions were NULL");
            }
          var values = parseValues(ngModel.$viewValue);
          selectize.addOption(newOptions);
          selectize.refreshOptions(false);
          if (options.mode === 'multi' && newOptions) {
            restoreInvalidValues(newOptions, values);
          }
          setSelectizeValue(values);
        }

Has anyone else had similar behaviour?

kbanman commented 7 years ago

Hey @tonysepia, I am not really maintaining this repository anymore, and frankly I'm surprised it still works with modern versions of angular :)

I'd be happy to transfer ownership of the repo to someone who is passionate about keeping it going.

tonysepia commented 7 years ago

Hello Kelly,

Thank you for getting back to me. In all honesty I am a total newbie to Angular so won't be able to contribute much myself.

But using this opportunity I would like to thank you for this great angular wrapper for selectize!

Best regards,

tonysepia commented 7 years ago

Just noticed that there is a pending Pull request that may fix this issue properly! Could you check it please?

kbanman commented 7 years ago

@tonysepia I have merged that PR

kbanman commented 7 years ago

The tests are not passing anymore, though I suspect that's mostly because of incompatibility with the latest version of angular. I will investigate further this evening, and maybe modernize the package a bit.