[[oktatas:web:angular|< Angular]] ====== Utánzás ====== * **Szerző:** Sallai András * Copyright (c) Sallai András, 2022 * Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]] * Web: https://szit.hu ===== Mock ===== A célobjektum helyettesítése utánzással, angolosan mocking. ===== Járművek ===== Készítünk egy interfészt, amit típusként használunk. export interface Vehicle { id: number; plate: string; brand: string; price: number; } A mock objektum: import { Vehicle } from "./vehicle"; export const VEHICLES: Vehicle[] = [ {id: 1, plate: 'DBA-834', brand: 'Opel', price: 830000}, {id: 1, plate: 'GDE-238', brand: 'Ford', price: 537000}, {id: 1, plate: 'EVG-389', brand: 'Fiat', price: 430000}, {id: 1, plate: 'GLC-241', brand: 'Opel', price: 895000}, {id: 1, plate: 'EDA-725', brand: 'Ford', price: 733000}, {id: 1, plate: 'LVA-234', brand: 'Ford', price: 935000} ]; Felhasználása: import { Component, OnInit } from '@angular/core'; import { VEHICLES } from '../mock-vehicles'; @Component({ selector: 'app-vehicle', templateUrl: './vehicle.component.html', styleUrls: ['./vehicle.component.css'] }) export class VehicleComponent implements OnInit { vehicles = VEHICLES; constructor() { } ngOnInit(): void { } }