1

I see the following code in a directive for our project, but am not sure what it does. Can someone explain what the first line does? Is this just how select2 is initiated?

 element.select2('val', ngModel.$viewValue);
                    if (isOpen) {
                        element.select2("close").select2("open");
                    }
Dave
  • 1,257
  • 2
  • 27
  • 58
  • It's basically setting a new value for select2,which can be done by using trigger too. – Namdeo Karande Dec 19 '17 at 05:36
  • hey @NamdeoKarande, can you explain that a little bit? What is 'val'? I don't see it declared anywhere in the code. Also is $viewValue used as a filter for search? Thanks. – Dave Dec 19 '17 at 14:20
  • 'val' is something where you tell select2 to update the value of dropdown.For more details refer - https://stackoverflow.com/questions/16969666/jquery-select2-set-default-value-from-an-option-in-list . Whereas $viewValue is to get the string value of the model.For more details refer this -https://stackoverflow.com/questions/19383812/whats-the-difference-between-ngmodel-modelvalue-and-ngmodel-viewvalue – Namdeo Karande Dec 20 '17 at 11:17

0 Answers0