I've been encountering an issue where I can't seem to add my jaddString to my array. Even though the string is created, it doesn't get added to the array. When I check my console in Google Chrome, I receive the following error: ReferenceError: aa is not defined
Here's the JavaScript code snippet:
var app = angular.module('kompileApp', []).controller('partsList', function($scope){
this.aa = addedArray;
this.aaString = addedArrayString;
this.jaddString = justAdded;
$scope.jadd = function(partId){
jaddString = parts[partId - 1].id + ': ' + parts[partId - 1].name + ', ' + parts[partId - 1].price;
aa[partId - 1] = jaddString;
};
});
// Array of parts
[
{
id: 1,
name: 'vitamine A',
price: 3,
canAdd: true,
added: false,
comp: '2, 5'
},
// Additional parts here...
];
var addedArray = new Array(parts.length);
var justAdded = '';
In my HTML file, I call the function within ng-click like this:
<div ng-controller="partsList as pl" class="ctrlDiv">
<li ng-repeat="part in pl.parts | orderBy:'+price'" ng-hide="part.added || !part.canAdd" class="plLi">
<button ng-click="jadd(part.id); pl.aa[part.id] = pl.jaddString" ng-show="part.canAdd" class="plistbutton">add</button>
</div>
</div>
I noticed that if I manually assign a value to my array, it displays correctly on my HTML page:
var addedArray = new Array(10);
addedArray[0] = 'lalala'