post.component.ts 1.04 KB
Newer Older
Erina JUVENTIN's avatar
Erina JUVENTIN committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
import { Component, Input, OnInit } from '@angular/core';
import {ɵvalidateStyleProperty} from '@angular/animations/browser';

@Component({
  selector: 'app-post',
  templateUrl: './post.component.html',
  styleUrls: ['./post.component.css']
})
export class PostComponent implements OnInit {

  @Input() postTitle: string;
  @Input() postloveIts: number;
  @Input() postContent: string;
  @Input() postDate: Date;

  post: {
    title: string,
    content: string,
    loveIts: number,
    created_at: Date
  }

  lastUpdate = new Promise((resolve, reject) => {
    const date = new Date();
    setTimeout(
      () => {
        resolve(date);
      }, 2000
    );
  });

  getLoveIts() {
    return this.postloveIts;
  }

  getColor() {
    if (this.postloveIts === 1) {
      return 'green';
    } else if (this.postloveIts === 0) {
      return 'red';
    }
  }

  onLove() {
    console.log('Love it !');
    this.postloveIts = 1;
  }

  onDontLove() {
    console.log('Dont Love it !');
    this.postloveIts = 0;
  }


  constructor() { }

  ngOnInit() {
  }

}