My code looks like:
$scope.filters = [{
name: 'cat1',
limit: 12
}, {
name: 'cat2',
limit: 12
}];
Can I simply call
limit: varname or $scope.name
does it need to be in a specific format?
My code looks like:
$scope.filters = [{
name: 'cat1',
limit: 12
}, {
name: 'cat2',
limit: 12
}];
Can I simply call
limit: varname or $scope.name
does it need to be in a specific format?
You have the Array of Javascript Objects that looks like this
[ // array
{ // index 0
name: 'cat1',
limit: 12
},
{ // index 1
name: 'cat2',
limit: 12
}
] // end array
That is assigned to $scope.filters. Now to access or set a specific objects contained in the array you must specify which element using the array index in square brackets.
console.log( $scope.filters[0] ); // {name: 'cat1', limit: 12}
Then you can use a property name to access the properties of one of the objects
var oldLimit = $scope.filters[0].limit; // = 12
$scope.filters[0].limit = oldLimit + 2; // = 14
So to recap $scope is an object, with the sub-element filters that is an array, that contains objects with the properties name and limit.
$scope.filters[index].propertyName