ngStorage icon indicating copy to clipboard operation
ngStorage copied to clipboard

TypeError: Illegal invocation

Open ghost opened this issue 10 years ago • 4 comments

Hi,

Getting this:

TypeError: Illegal invocation
    at isArrayLike (angular.js:276)
    at forEach (angular.js:332)
    at copy (angular.js:930)
    at copy (angular.js:899)
    at copy (angular.js:943)
    at Object.copy (angular.js:899)
    at $get.$storage.$apply (ngStorage.js:176)
    at angular.js:17744
    at completeOutstandingRequest (angular.js:5490)
    at angular.js:5762

Error message goes away if I disable "_last$storage = angular.copy($storage);" on line 176 of ngStorage.js

Any thoughts are really appreciated!

AngularJS 1.4.5 Material Design, from master ngStorage 0.3.9

Thanks, Dennis

ghost avatar Sep 04 '15 21:09 ghost

Hoy,

Thanks for the report. Any chance you could provide an example of how you use ngStorage in your app?

I use it like this in an app that uses AngularJS 1.4.5, ngMaterial 0.10.1 and ngStorage 0.3.9:

app.service('Leads', ['$rootScope', '$log', '$localStorage',
  function ($rootScope, $log, $localStorage) {
    if (!$localStorage.Leads) {
      $localStorage.Leads = [];
    }
    var leads = $localStorage.Leads;

    // ... snip ...

    return leads;
  }]);

egilkh avatar Sep 05 '15 04:09 egilkh

Hey,

My use case:

  1. Calling mdDialog to create a modal
  2. Injecting $localStorage into the modal's controller to load previously stored vars
 angular
        .module('app')
        .controller('BlogImageDialogController', BlogImageDialogController);

    BlogImageDialogController.$inject = ['$scope', '$mdDialog', ..... '$localStorage'];
    function BlogImageDialogController($scope, $mdDialog, ...... localStorage) {
...

That error was appearing just because of using localStorage as DI (weird). Even after removing all the code from the modal controller I was still getting this error.

( I've found a work-around for my case though: i'm passing vars using locals: {} obj in the mdDialog config, thus avoiding $localStorage in the modal controller at all. )

Hope this helps! D.

ghost avatar Sep 05 '15 05:09 ghost

Hi.. After a little research i found the cause of the issue. but fixing it is upto dev's.

So you are using this to store files in the local storage. so after selecting a file, the file is injected into the localstorage but in a different way rather than as a file because angular.copy cannot copy files and in line number 178 we have

temp$storage = angular.copy(_last$storage);

This copies the file to the temp$storage incorrectly making the angular.equals throw error on the next digest cycle. So this is an issue with angular.copy not supporting deep copy of files.

Hope this helped.

rkabrahpudi avatar Oct 04 '17 08:10 rkabrahpudi

Hi, any update or workarounds? Can we catch this exception and ignore it?

DanielRuf avatar Feb 20 '19 13:02 DanielRuf