aboutsummaryrefslogtreecommitdiff
path: root/sandbox/TestIvanLjubisavljevic/frontend/src/app/homepage/homepage.component.ts
blob: 4ebea54dc6e51e9735f17a003e8b1664c13cdd03 (plain) (blame)
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
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Laptop } from '../models/laptop';
import { LibraryServiceService } from '../services/library.service';

@Component({
  selector: 'app-homepage',
  templateUrl: './homepage.component.html',
  styleUrls: ['./homepage.component.css']
})
export class HomepageComponent implements OnInit {
  laptops?:Laptop[]
  constructor(private library : LibraryServiceService, private router:Router) { }

  ngOnInit(): void {
    
    this.library.dajLaptopove().subscribe(laptopovi =>{
      this.laptops = laptopovi
    })
  }

  pogledaj(id:String)
  {
    this.router.navigate(["/laptop/"+id])
  }

  izmeni(laptop:Laptop)
  {
    this.router.navigate(['/izmeniLaptop/'+laptop.id])
  }

  obrisi(laptop:Laptop)
  {
    this.library.obrisiLaptop(laptop.id).subscribe(req=>{
      
        this.library.dajLaptopove().subscribe(laptopovi =>{
          this.laptops = laptopovi
        })
    })
  }

}