Answer the question
In order to leave comments, you need to log in
How to pass multiple values from $scope to view in angularjs?
There is a controller that, firstly, takes some data from json and saves it to a variable, and secondly, it counts the difference between two dates as a loop.
app.controller('myController', function($scope, loadData) {
loadData.success(function (data) {
$scope.Info = data;
for(i=0; i<data.length; i++) {
var dateFormat = 'DD/MM/YYYY HH:mm:ss';
var end = moment(data[i].date);
var now = moment();
var difference = moment(endDate,dateFormat).diff(moment(currentDate,dateFormat));
var duration = moment.duration(timeDIff);
var formatDuration = timeDuration.format("d дня hh часов mm минут ss секунд");
console.log(formatDuration);
$scope.cd = formatDuration ;
};
});
});
<div>
<div ng-repeat="item in Info">
<h3>{{item.name}}</h3>
<p>До окончания:<br />{{cd}}</p>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
$scope.calcTime = function(date){
var dateFormat = 'DD/MM/YYYY HH:mm:ss';
var end = moment(date);
var now = moment();
var difference = moment(endDate,dateFormat).diff(moment(currentDate,dateFormat));
var duration = moment.duration(timeDIff);
var formatDuration = timeDuration.format("d дня hh часов mm минут ss секунд");
console.log(formatDuration);
return formatDuration;
}
<div>
<div ng-repeat="item in Info">
<h3>{{item.name}}</h3>
<p>До окончания:<br />{{calcTime(item.date)}}</p>
</div>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question