Я пытаюсь преобразовать эту функцию JavaScript в AngularJS, но получаю несколько ошибок, поскольку я новичок в AngularJS.
var array = [5, 5, 7, 9, 9, 9];
var max = array[0],
total = 0;
array.forEach((a) => {
if (a == max) {
total += max;
} else if (a > max) {
max = total = a;
}
});
console.log("total:", total);
Теперь var array[]
приходит из GET данных, и я сделал это в своем коде AngularJS.
$scope.List = getAllList;
$scope.deptime =function (){
$scope.array = $scope.List.Time;
console.log($scope.array);
$scope.max = $scope.array[0], $scope.total = 0;
angular.array.forEach((a)=>{
if(a==$scope.max){
$scope.total+=$scope.max;
}
else if(a>$scope.max){
$scope.max = $scope.total = a;
}
});
console.log("total:"+$scope.total);
};
$scope.deptime();
ИтакЯ сталкиваюсь с этой ошибкой:
TypeError: Невозможно прочитать свойство '0' из неопределенного
Где я иду неправильно?
РЕДАКТИРОВАТЬ: - Я получаю ответ от службы в этой части: - $scope.List = getAllList;