OK, yeah, I know this is basic stuff, but it's got me by you know what.
Here's the code:
myApp.controller('keyExpController', function ($scope, KeyExpDataService) {
var ctrlExp = this;
ctrlExp.keyExp = [];
$scope.company = {};
ctrlExp.achKeys = {
company: [{
achieves: [],
details: {
super: "",
whyleft: ""
}
}]
};
$scope.keyachievements = [];
$scope.compName = null;
ctrlExp.fetchKeyExp = function () {
//Resume Data
KeyExpDataService.getKeyExpData().then(function (result) {
ctrlExp.keyExp = result.data.resume.proexperience;
console.log("Result: " + ctrlExp.keyExp);
$scope.groupBy(ctrlExp.keyExp.length);
});
};
ctrlExp.fetchKeyExp();
// I group the friends list on the given property.
$scope.groupBy = function (nbrComps) {
//Set the global value for number of companies
nbrCompanies = nbrComps;
var compValue = "_INVALID_GROUP_VALUE_";
for (var i = 0; i < nbrComps; i++) {
$scope.keyachievements = ctrlExp.keyExp[i].keyachievements;
if (ctrlExp.keyExp[i].companyat !== compValue) {
$scope.company = [{
achievements: [],
details: {
companyName: ctrlExp.keyExp[i].companyat,
super: ctrlExp.keyExp[i].supervisor,
whyleft: ctrlExp.keyExp[i].reasonforleaving
}
}];
compValue = $scope.company.companyName;
$scope.compName = compValue;
//It's HERE, with the first line that I continually get the following error:
//TypeError: Cannot read property 'achieves' of undefined
//at Scope.$scope.groupBy (controllers.js:151)
//This is line 151 just below:
achievements.company[i].achieves[i] = $scope.keyachievements;
achievements.company[i].details.super = ctrlExp.keyExp[i].supervisor;
achievements.company[i].details.whyleft = ctrlExp.keyExp[i].reasonforleaving;
ctrlExp.achKeys.company[i].achieves[i] = $scope.keyachievements;
ctrlExp.achKeys.company[i].details.super = ctrlExp.keyExp[i].supervisor;
ctrlExp.achKeys.company[i].details.whyLeft = ctrlExp.keyExp[i].reasonforleaving;
}
}
};
});
Now what I'm doing is fine until I hit this in the controller. My OBJECT looks like this broken out for brevity:
ctrlExp.achKeys = {
company: [{
achieves: [],
details: {
super: "",
whyleft: ""
}
}]
};
I cannot figure out, for the life of me, yeah, it's got to be because I'm over 50, why I cannot assign anything to the first part of the object:
THIS: ctrlExp.achKeys.company[0].achieves[0] = $scope.keyAchievements
The $scope.keyAchievements hold all the bullets for a particular company. There could be "n" number of companies on a person's resume. Hence, I'm looping through the companies to get the name of the company and the "key achievements" that reside "under" that company for a person.
That's pretty much it.
I'll post the "service" but this site is a cut for my own site, not posted yet, that I'll be using as a template for future considerations. Once I get this, I'm golden.
Thanks everyone for your contributions to our craft.
achievementsvariable come from? It is not declared in this code. Also,$scope.company.companyNamedoesn't exist and will always beundefined. It is probably$scope.company.details.companyNameinstead.