Selects droplist inside ngTable loses its scope
If I put the Selects (select.js) droplist inside ngTable, and try to show the selection from outside the table, it loses its scope and doesn't show the selection. Hopefully, I was able to explain this.
Here's the preview. In the preview, you will see a select droplist which has two output locations. One inside the table which works and another outside the table which doesn't.
http://plnkr.co/edit/tQYmRrTjXOhTohsESpNo?p=preview
http://plnkr.co/edit/d6UiyUaUjvp1vG2CQV79?p=preview
If you use ngModel, there must be a dot somewhere to persist value accross scopes (as only pointers can cope with mutliple references).
Your example works but still showing the wrong value.
I had to modify angular-strap.js and add scope.$apply(). Here's what I did.
$select.update = function (matches) { scope.$matches = matches; if (controller.$modelValue && matches.length) { if (options.multiple && angular.isArray(controller.$modelValue)) { scope.$activeIndex = controller.$modelValue.map(function (value) { return $select.$getIndex(value); }); } else { scope.$activeIndex = $select.$getIndex(controller.$modelValue); } } else if (scope.$activeIndex >= matches.length) { scope.$activeIndex = options.multiple ? [] : 0; } scope.$apply(); };
@shojib is right! I added an scope.$apply() on the $select.update, was a bug that took my morning jaja
$select.$updateActiveIndex = function () { if (controller.$modelValue && scope.$matches.length) { if (options.multiple && angular.isArray(controller.$modelValue)) { scope.$activeIndex = controller.$modelValue.map(function (value) { return $select.$getIndex(value); }); } else { scope.$activeIndex = $select.$getIndex(controller.$modelValue); } } else if (scope.$activeIndex >= scope.$matches.length) { scope.$activeIndex = options.multiple ? [] : 0; } scope.$apply(); };
If you want, I can do a PR and contribute with the project more, I use it everyday in a complex app. Greetings. Emiliano.
Found the cause: In Documentation is wrote : $scope.selectedIcon = "Globe"; $scope.selectedIcons = "[]"; $scope.icons = "[{"value":"Gear","label":"<i class="fa fa-gear"> Gear"},{"value":"Globe","label":"<i class="fa fa-globe"> Globe"},{"value":"Heart","label":"<i class="fa fa-heart"> Heart"},{"value":"Camera","label":"<i class="fa fa-camera"> Camera"}]";
But should be: $scope.selectedIcons = []; $scope.icons = [ {value: 'Gear', label: 'Gear'}, {value: 'Globe', label: 'Globe'}, {value: 'Heart', label: 'Heart'}, {value: 'Camera', label: 'Camera'} ];
NO DOUBLE QUOTES !!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.