Within my HTML markup, I have a ng-init="find()"
which triggers this particular function:
$scope.find = function()
{
$scope.vehicles = Vehicles.query();
$scope.vehiclesQtd = $scope.vehicles.length;
};
The issue arises when even though the vehicles are successfully displayed in the view, the value of $scope.vehiclesQtd
is consistently showing as 0
.
To address this, I implemented a watcher to update $scope.vehiclesQtd
whenever a vehicle is added or removed:
$scope.$watch('vehicles', function()
{
$scope.vehiclesQtd = $scope.vehicles.length;
console.log(JSON.stringify($scope.vehiclesQtd, null, 4));
});
Despite this effort, the console keeps reporting a value of 0
for $scope.vehiclesQtd
and an empty array for $scope.vehicles
, even though the vehicles are visibly rendered on the screen.
This information is crucial for setting a limit on creating new vehicles.