2014-07-08 72 views
0

感謝您的所有輸入,但現在我已經或多或少有類似的問題了,我有數據需要存儲在sql-server數據庫中,當我嘗試發佈它的數據沒有被寫入。我的代碼結構是否正確?如何使用角度js將數據發佈到sql server

self.CurrentDowntimeEvent = { 
     method: 'POST' 
     , url: 'someurl/test' 
     , data: { 
      DepartmentId: cookie 
     , CategoryId: -1 
     , Comment: "" 
     , DowntimeStart: "2014-07-07T10:00:00" 
     , DowntimeEnd: null 
     } 
     , headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'} 
    }).success(function (data) { 
     console.log(data); 
    }).error(function (data) { 
    }); 

回答

1

$http是應該被注入到控制器中的服務,所以你不應該需要self.引用它:

self.RecordsSave = function() { 
    for (var i = 0; i < self.Employees.length; i++) { 
     var employee = self.Employees[i]; 
     var params = { 
      CompanyNumber: employee.ClockNumber, 
      Department: employee.DepartmentID, 
      Present: employee.Present, 
      Reason: employee.AbsentCode 
     }; 
     $http.post(SAVE_EMPLOYEERECORDS, { 
      params: params 
     }).success(function (data) { 
      alert("testing"); 

     }); 
    } 
}; 
+0

什麼是自我?爲什麼使用它? – micronyks

+0

通常'self'用作父對象的引用,所以你知道它引用了什麼對象,而不是依賴於'this'這個對象。 '(function(){var self = this; var internalFunction = function(){self.hello();};}());' - 我假設在這種情況下它是什麼 – CodingIntrigue

+0

但是如何自我。 RecordsSave被叫? – micronyks

相關問題