import { Component , OnInit } from '@angular/core' ; import { Category } from 'src/app/models/category' ; import { CategoryService } from 'src/app/services/category.service' ; @ Component ( { selector : 'app-category' , templateUrl : './category.component.html' , styleUrls : [ './category.component.css' ] } ) export class CategoryComponent implements OnInit { categories : Category [ ] = [ ] ; currentCategory : Category ; constructor ( private categoryService ) { } ngOnInit ( ) { this . getCategories ( ) ; } getCategories ( ) { this . categoryService . getCategories ( ) . subscribe ( response => { this . categories = response . data ; } ) ; } setCurrentCategory ( category ) { this . currentCategory = category ; } getCurrentCategoryClass ( category ) { if ( category == this . currentCategory ) { return "list-group-item active" ; } else { return "list-group-item" ; } } getAllCategoryClass ( ) { if ( ! this . currentCategory ) { return "list-group-item active" ; } else { return "list-group-item" ; } } }