angular-local-storage
angular-local-storage copied to clipboard
Binding all keys to the $rootScope
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 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.