角度サービスを使用してテーブル行を削除しようとしていますが、残念ながらその方法はわかりません。同じコントロールで複数のサービスを使用しているため、サービスを使用して行う必要があります。角度角サービスを使用してテーブルから行を削除します
<script>
var myApp = angular.module("myApp", []);
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;
}
}]);
myApp.controller('myController', ['$scope', 'allCurrentSettingsService',
function ($scope, allCurrentSettingsService) {
$scope.allSettings = '';
allCurrentSettingsService.getList().then(function (value) {
$scope.allSettings = value;
});
}
]);
</script>'
そして、これが私のHTMLです:あなたがしたい場合は、フロントエンドから
[HttpPost]
public static void DeleteRecord(int settingID)
{
try
{
using (SqlConnection conn = new SqlConnection(connStringApps))
{
conn.Open();
using (SqlCommand command = new SqlCommand("DeleteCurrentRecord", conn))
{
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add("@SettingId", SqlDbType.VarChar).Value = settingID;
command.ExecuteNonQuery();
command.Parameters.Clear();
}
conn.Close();
}
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
}
助けてくれてありがとう。コントローラーから行を削除する方法を説明できますか?コードを含めると非常に役に立ちます – user6440175
@ user6440175答えが更新されました。実際にあなたの答えが得られれば他の人の答えとして選択してください:) – Maher
ありがとうございます。私は自分のコードを更新し、コントローラにdeleteメソッドを追加しました。どのように私はこのメソッドを呼び出すことができ、削除する値を渡すことができますか教えてください。メソッドは 'HTTP POST'でなければならない – user6440175