0
將數據集的大小傳遞給角度服務。我正在嘗試將數據集(計數)的大小傳遞給角度服務。我剛開始工作與角度和任何幫助,不勝感激。將數據集的大小傳遞給角度服務
的Controler:
public JsonResult GetAllCurrentSettings()
{
var jsonString = string.Empty;
string query = "SELECT * from test";
try
{
using (SqlConnection conn = new SqlConnection(connStringApps))
{
conn.Open();
using (SqlCommand command = new SqlCommand(query, conn))
{
DataTable dt = new DataTable();
using (SqlDataReader rdr = command.ExecuteReader())
{
dt.Load(rdr);
}
jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(dt, Formatting.None);
return Json(jsonString);
}
}
}
catch (Exception ex)
{
Console.Write(ex.ToString());
return Json(jsonString);
}
}
角服務
myApp.service('allCurrentSettingsService', ['$http', '$q', function ($http, $q) {
var allSettings = null;
this.getList = function() {
var def = $q.defer()
if (allSettings) {
def.resolve(allSettings);
} else {
$http.post('GetAllCurrentSettings')
.then(function (response) {
var response = $.parseJSON(response.data)
allSettings = response;
def.resolve(allSettings);
});
}
return def.promise;
}
}]);
謝謝。我怎樣才能通過服務計數? – user6440175
返回Json(<任何類型的對象>)。這個幫助器方法將對象轉換爲JSON。只需使用:return Json(count) – scokmen