tech

Table of Content

Install

Ketik perintah dibawah untuk menginstall swal2

npm install sweetalert2

Load Swal2

import { Component } from '@angular/core';
import { Router } from '@angular/router';
import Swal from 'sweetalert2';
 
@Component({
  selector: 'app-login-nik',
  imports: [],
  templateUrl: './login-nik.component.html',
  styleUrl: './login-nik.component.css'
})
export class LoginNikComponent {
  nik: string = ''; 
 
  constructor(private router: Router) {}
 
  login(nik: string) {
    if (nik == '105000464') {
      this.router.navigate(['/home']); 
    } else {
      Swal.fire("Gagal","NIK tidak valid!","error"); 
    }
  }
}

Penggunaan:

  • import Swal from 'sweetalert2' → import module swal2.
  • Swal.fire("Gagal","NIK tidak valid!","error") → penggunaan swal 2 one line.

Date: 24-03-2025