javascript - Datepicker on AngularJS error with values -


What I'm trying to do here is when a user StartDate and End date When he clicks on the previous arrow, he should get the data 7 days in advance to see the progress.

Javascript :

  $ scope.getDiffPrev = function (startup, endadet, compute def) {var start = startDate; Var date1 = (start.getDate (-7); Var month1 = (start.getMonth () + 1); Var year1 = start.getFullYear (); Var end = endDate; Var date2 = (end.getDate () -7); Var month2 = (end.getMonth () + 1); Var year2 = end.getFullYear (); $ http.get ('/ admin / api / stats? start =' + date1 + '-' + 1 month '-' + 1 year '& amp; end =' +2 date + + '-' +2 months + + '-' + 2 + 'and computeDiff = true'). Success (work) {$ scope.stats = data;}); }   

HTML :

  & lt; Label & gt; From & lt; / Label & gt; & Lt; Input type = "text" datespeak-popup = "DD-MM-yay" ng-model = "start date" /> & Lt; Label & gt; / Labels & gt; & Lt; & Lt; Input type = "text" datepicker-popup = "dd-MM-yyyy" ng-model = "endDate" /> & Lt; Button class = "BTN BTN-Success" ng-click = "leaddiffprrave (startdate, endadet, compudiff)" & gt; & Larr; & Lt; / Button & gt;    

Do not we all like Javascript date? ;) var start = angular.copy (start date) start.setDate (start.getDate () + computeDiff); Var date1 = start.getDate (); Var month1 = start.getMonth () + 1; // I hate them for this one- var year1 = start.getFullYear ();

In line start.setDate (start.getDate (+ computeDiff); We use date () 's Internal calculation to get the correct date.

Edit : If you can add other libraries, look at

  moment () Enter the subtract ('day', 7) format ('yourFormatStringHere')    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -