angular-strap icon indicating copy to clipboard operation
angular-strap copied to clipboard

Selects droplist inside ngTable loses its scope

Open shojib opened this issue 12 years ago • 6 comments

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

shojib avatar Jan 21 '14 19:01 shojib

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).

mgcrea avatar Jan 22 '14 15:01 mgcrea

Your example works but still showing the wrong value.

shojib avatar Jan 24 '14 16:01 shojib

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 avatar Jan 29 '14 16:01 shojib

@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.

Epotignano avatar May 05 '14 18:05 Epotignano

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 !!

mrvalb avatar Jan 15 '15 15:01 mrvalb

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.

lock[bot] avatar Jan 26 '19 09:01 lock[bot]