< Angular

Utánzás

Szerző: Sallai András

Copyright © Sallai András, 2022

Licenc: 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

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 { } }