Stack Exchange
Getting TypeError: Cannot set property 'scripts' of undefined
I have the following AngularJS code:
HTML:
<input type="text" class="form-control" id="repoInput" style="margin: 10px 0 10px 0"
                                       placeholder="Stored Procedures"
                                       ng-model="procedureInput"
                                       uib-typeahead="key for key in getScripts(selected.branchClone, selected.type) | filter:$viewValue | limitTo:10"
                                       typeahead-on-select='addStoredProcedure($item, selected);procedureInput = "";'
                                       typeahead-loading="templateLoading"
                                       typeahead-wait-ms="100" />
$scope.getScripts = function (repo, template) {
items.then(function (payload) {
            $scope.repos[template] = template;
            $scope.repos[template][repo] = repo;
            console.log($scope.repos[template]);
            console.log(repo);
            console.log($scope.repos[template][repo]);
            $scope.repos[template][repo]["scripts"] = payload.data.value;
            deferred.resolve(payload.data.value
                .map(function (x) {
                    return x["path"];
                }));
        });
}

I do have values for template variable and repo variable. But, still, I am getting an error on 
$scope.repos[template][repo]["scripts"] = payload.data.value; saying 
TypeError: Cannot set property 'scripts' of undefined

Show the code where repo is defined. That likely holds the key.

sry, just updated my question.

What does the console.log output? Is repo an object?

What is the type of repo? It seems it's an object, that can't be stored inside of a map structure.

For 3 console log statements, I am getting following outputs: Database, master, undefined. So as you can see, I am getting the value of repo but still getting undefined for console.log($scope.repos[template][repo]);

Post a sample of data for $scope.repos and a sample call to $scope.getScripts

@lealceldeiro $scope.repos looks like { template: { repo: { "": "" } } } and I have added html to the question for $scope.getScripts call.

I think you need to revisit how you are using bracket notation. I think you are probably looking for $scope.repos[‘template’] = template and something similar for your role assignment. What is the shape of the data stored in template and role?
