javascript - printing dynamic value of js file inside html -
i'm working on dynamic web application. i'm getting response java spring controller , displaying results in html page. have many fields(like id, spread%,createddate,opinion,comments...) on webpage. when printing values directly on webpage, date printed number(1485882060000) on webpage. converting date object in javascript file using new date(val) shown below.
myservice.getresults(id).then( function(response) { $scope.results = response; angular.foreach($scope.results,function(value,key){ var startdaterange = new date(value.startdate);/*want print value in place of {{data.startdate}} in results.html*/ var enddaterange = new date(value.enddate);/*want print value in place of {{data.enddate}} in results.html*/ }); }, function(errresponse){ console.error('error in getresults'); }); results.html
<div> <table> <tr> <th style="width:5%;">id</th> <th style="width:5%;">spread%</th> <th style="width:15%;">startdate</th> <th style="width:15%;">enddate</th> <th style="width:15%;">opinion</th> <th style="width:20%;">comments</th> </tr> <tr ng-repeat="data in results <td >{{data.id}}</td> <td>{{data.spread}}</td> <td>{{data.startdate}}</td> /*how print startdaterange value javascript file*/ <td>{{data.enddate}}</td> /*how print enddaterange value javascript file*/ <td>{{data.opinion}}</td> <td>{{data.comments}}</td> </tr> </table> </div> please advice how print javascript variable values in html dynamically. above code, i'm getting date fields printed in html page mentioned below.
in place of {{data.startdate}} value shown : 1485882060000 .
in place of {{data.enddate}} value shown : 1490298780000
instead, want print modified javascript variable values startdaterange , enddaterange in iteration.
as far can understand, want convert epoch timestamp(milliseconds since 1st jan, 1970) date. can use angular's date filter(https://docs.angularjs.org/api/ng/filter/date) convert value particular date format.
<tr ng-repeat="data in results <td >{{data.id}}</td> <td>{{data.spread}}</td> <td>{{data.startdate | date:'yyyy-mm-dd hh:mm:ss'}}</td> <td>{{data.enddate | date:'yyyy-mm-dd'}}</td> <td>{{data.opinion}}</td> <td>{{data.comments}}</td> </tr>
Comments
Post a Comment