角度cliアプリでアイテムを削除しようとしています。私は警告として甘い警告を使用して、私はリストから項目を削除したい。ここにそのコードがあります。このコードはタイスクリプトファイルです。角2 - スウィートアラートコールバック機能が動作しません
import { AuthenticationService } from '../../../services/authentication.service';
declare var swal: any;
export class AdminUsersComponent implements OnInit {
constructor(
private authService: AuthenticationService,
) { }
deleteUser(id) {
let userData = {
user_id: id
};
swal({
title: "Are you sure?",
text: "You will not be able to recover this!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
}, function(){
this.authService.deleteUser(userData).subscribe(data => {
// response
});
});
}
}
問題を削除すると「this.authserivce」が定義されていないというエラーが表示されます。私は確認として甘い警告を使用しない場合、それは正常に動作しています。私はコールバック関数でパラメータを渡す必要があると推測しているが、私は何を渡す必要があるか分からない。だから私はこれを解決する方法は?
は、あなたが全体のコードを送ることができますか? 'authService.deleteUser'とは何ですか? – Manav
@manav私はコードを更新しました。見てみましょう – parth
多分sweetalertは 'this'を上書きしていますか? – Manav