Activity 33: Angular Recipe Grid
Create a List of Object Data Structures
recipe.service.ts
recipe.model.ts
recipe.component.ts
recipe.component.html
document it on hashnode.com
include firebase hosting link and github link
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
background-color: #ca4848;
padding: 1rem;
}
.recipe-grid {
display: grid;
gap: 1rem;
grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 768px) {
.recipe-grid {
grid-template-columns: repeat(3, 1fr);
}
}
@media (min-width: 1024px) {
.recipe-grid {
grid-template-columns: repeat(5, 1fr);
}
}
.recipe-grid__item {
background: #fbc5c5;
border: 1px solid #fbc5c5;
border-radius: 8px;
text-align: center;
padding: 1rem;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.recipe-grid__image {
width: 100%;
height: auto;
aspect-ratio: 1 / 1;
object-fit: cover;
border-radius: 4px;
margin-bottom: 0.5rem;
}
.recipe-grid__name {
font-size: 1rem;
font-weight: bold;
margin-bottom: 0.5rem;
}
.recipe-grid__ingredients {
font-size: 0.5rem;
margin-bottom: 0.5rem;
}
.recipe-grid__button {
background-color: #2890d0;
color: #2890d0;
border: none;
padding: 0.5rem;
border-radius: 5px;
cursor: pointer;
}
.recipe-grid__button:hover {
background-color: #2890d0;
}
import { RecipeService } from './../../services/recipe.service';
import { Component, OnInit } from '@angular/core';
import { RecipeModel } from '../recipe';
@Component({
selector: 'app-recipe',
templateUrl: './recipe.component.html',
styleUrl: './recipe.component.css'
})
export class RecipeComponent implements OnInit{
recipeList: RecipeModel[] = [];
constructor(private recipeService: RecipeService) {}
ngOnInit(): void {
this.recipeList = this.recipeService.getRecipe();
}
}
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RecipeComponent } from './recipe.component';
describe('RecipeComponent', () => {
let component: RecipeComponent;
let fixture: ComponentFixture<RecipeComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RecipeComponent]
})
.compileComponents();
fixture = TestBed.createComponent(RecipeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});