import { DiaryService } from './../diary.service';
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Diary } from '../Diary';


@Component({
  moduleId: module.id,
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
  diarys: any;

  constructor(private http: HttpClient, private service: DiaryService) {}

  ngOnInit() {
    this.getDiarys();
  }

  getDiarys() {
    this.service.getDiarys().subscribe(res => {
      this.diarys = res;
    });
  }

  deleteDiary(id,topic) {
    if(confirm("ยืนยันการลบข้อมูล : "+topic)){
    this.service.deleteDiary(id).subscribe(res => {
      console.log('Deleted');
      this.getDiarys();

    });
  }
  }


}
