2017-04-24 49 views
0

我試圖將curent日期發送給我的restapi,以便我可以使用它。我分配和傳遞參數超過$http.post方法是這樣的:

(function() { 
     var app; 

     app = angular.module('vinclucms.sales'); 

     app.controller('FilterContactsListCtrl', [ 
     '$scope', '$http', function($scope, $http) { 
      var nextContactListUpdateFailed, nextContactListUpdateSuccess; 
      $scope.selectDate = null; 
      $scope.doAction = function() { 
      var data; 
      data = { 
       date: $scope.selectDate 
      }; 
      return $http.post("/sales/lead_contact/", data).then(nextContactListUpdateSuccess, nextContactListUpdateFailed); 
      }; 
      nextContactListUpdateSuccess = function() { 
      return ClientNotifications.showNotification("Success", "Contact Leads list page was updated", "success"); 
      }; 
      return nextContactListUpdateFailed = function() { 
      return ClientNotifications.showNotification("Alert", "Failed to update contact leads list page", "alert"); 
      }; 
     } 
     ]); 

    }).call(this); 

目前設爲null,我有與在它返回None當我調試我認爲剩下的問題,問題是我怎麼能傳遞當前日期超過$http.post方法?

日期時間選取場我用它來選擇日期

<div class="flex-grid" 
      ng-controller="FilterContactsListCtrl"> 
     <div class="row"> 
      <div class="cell size-p20 padding10"> 
       <label>Select Date: *</label> 
       <div class="full-size"> 
        <div class="input-control text" data-other-days="true" 
         data-week-start="1" 
         data-role="datepicker" date-format="mmmm d, yyyy"> 
         <input type="text" ng-model="selectDate" ng-change="doAction()"/> 
         <button class="button"> 
          <span class="mif-calendar"></span></button> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
+0

凡被設置成用'null'?在你的'/ sales/lead_contact /'端點方法中?你能否提供該方法的代碼? – eminlala

+0

其他所有事情都發生在'djangorestframework'視圖內,所以我不想混淆,我對這部分純粹的角碼感興趣,我會嘗試添加一個過濾器,但如果你有另一個建議,米打開聽到@eminlala – PetarP

回答

1

你可能需要做的日期轉換,你可以嘗試像下面,

var data; 
data = { 
    date: $filter('date')(new Date($scope.selectDate), 'MM/dd/yyyy', 'US') 
}; 

在當前日期的情況下, :

var data; 
data = { 
    date: $filter('date')(new Date(), 'MM/dd/yyyy', 'US') 
}; 

注:請注$過濾器到控制器中