angular-local-storage icon indicating copy to clipboard operation
angular-local-storage copied to clipboard

Binding all keys to the $rootScope

Open iltera opened this issue 9 years ago • 1 comments

I wonder how would binding all the keys to scope be possible. I just need to show the length of the total keys in the localStorage (created by this plugin) on my header all the time and change it automatically if the length increases or decreases.

Any thoughts?

iltera avatar Apr 11 '15 22:04 iltera

@iltera If you don't want to deal with $scope.$watch and you simply just want to display the number of keys on your page, use Angular's two-way data-binding.

Assuming you're using Vanilla JS, In the controller that manages that page, inject localStorageService and assign it to some property of the scope (E.g., $scope.storage = localStorageService) then wherever you want the number of keys to show, use

    {{ ctrl.storage.keys().length }}

assuming your controller was named ctrl with the "controllerAs" syntax. The digest cycle will cause the template to update with the correct value.

g2graman avatar Feb 18 '16 00:02 g2graman