javascriptarraysangularjsillegalaccessexception

Angular JS illegal access


I'm new to Angular JS. I've recently bumped into this weird error:
illegal access
(anonymous function) @ angular.js:12416$get @ angular.js:9203
(anonymous function) @ angular.js:17785
completeOutstandingRequest @ angular.js:5490
(anonymous function) @ angular.js:5762

I have search over the internet regarding this error but it isn't that famous.

The Idea:
So I have a dropdown selection of groups. And then, when its value has changed, groupSelOnChange() will fire and the selection of categories will be populated. The dropdown selection of categories depends on the selected group.id;

Please note that everything is working fine on my local machine. The error bump into me when I have uploaded the app on shared hosting.

These are my models

<button type="button" class="btn btn-primary"
 ng-model="vm.groupSel"
 bs-options="sel.id as sel.name for sel in vm.groups"
 bs-select ng-change="vm.groupSelOnChange(vm.groupSel)"
 placeholder="Choose your category">
    Action <span class="caret"></span>
</button>

<button type="button" class="btn btn-primary"
 ng-model="vm.categorySel"
 bs-options="sel.id as sel.name for sel in vm.categories"
 bs-select ng-change="vm.categorySelOnChange(vm.categorySel)"
 placeholder="Choose">
    Action <span class="caret"></span>
</button>

And on my controller

function groupSelOnChange(sel) {        
    searchObj['id'] = parseInt(sel);
    $timeout(function(){
        var found = $filter('filter')(vm.groups, searchObj, true);
        return vm.categories = found[0].categories;
    }, 500);
}

Initially I have populated the vm.groups with a factory using laravel and its "->with" so categories will be under groups.categories. As for vm.categories, I have set it to an empty array temporarily until groupSelOnChange has fired.

When I tried console.log, the illegal access error is showing on the line :

$filter('filter')(vm.groups, searchObj, true);


Can someone help me?


Solution

  • I have discovered a workaround just to avoid this statement
    $filter('filter')(vm.groups, searchObj, true);

    and did modification on my controller from this:

    function groupSelOnChange(sel) {        
        searchObj['id'] = parseInt(sel);
        $timeout(function(){
            var found = $filter('filter')(vm.groups, searchObj, true);
            return vm.categories = found[0].categories;
        }, 500);
    }
    

    to this:

    function groupSelOnChange(sel) {        
        var found = $filter('filter')(vm.groups, function(value, index, array) {
            if (value.id == sel) {
                return value;
            }
        }, true);
        vm.categories = found[0].categories;
    }
    

    I think I'm having a problem specifically on searchObj. And since it has been removed, everything's working fine.