I am currently developing a budgeting application and I have a component that is responsible for holding values that I want to pass to an array stored in a separate file. While I can retrieve data from the array, I am facing difficulty in figuring out how to add data to the array.
Is there a method to accomplish this task or would it be necessary to create another component and store the array within that component?
input.component.ts
import { Component, OnInit, Input } from '@angular/core';
import { USERS } from '../mock-users';
import { Users } from '../Users';
@Component({
selector: 'app-input',
templateUrl: './input.component.html',
styleUrls: ['./input.component.css']
})
export class InputComponent implements OnInit {
@Input() description: string;
@Input() date: Date;
@Input() amount: number;
@Input() category: string;
constructor() { }
ngOnInit() {
}
addExpense() {
console.log('expense added');
}
}
mock-users.ts
import { Users } from './Users';
export const USERS: Users[] = [
{
id: 1,
name: 'Keenan',
username: 'keenan.kaufman',
password: 'admin',
expenses: [{
date: new Date('2019-5-2T00:00:00'),
description: 'Electric Bill',
amount: 42,
category: 'Utilities'
},
{
date: new Date('2019-5-2T00:00:00'),
description: 'Rent',
amount: 350,
category: 'Rent'
}]
}
];