I need help retrieving data from an array in my services using a get function. I've tried using the .filter and .find functions, but I'm struggling with the execution and haven't been able to retrieve the data successfully. I know this may be a basic question, but I'm new to this and any assistance would be greatly appreciated.
tracker-data.ts:
export class TrackerData {
entry?: number;
exit?: number;
clicks: string[] = [];
url?: string;
public get clickCount(): number
{ return this.clicks.length; }
}
tracker.service.ts
import { Injectable } from '@angular/core';
import { TrackerData } from '../modules/tracker-data';
@Injectable({
providedIn: 'root'
})
export class TrackerService {
websiteData: TrackerData[] = [];
public count = 0;
constructor() { }
addTrackerData(trackerData: TrackerData): void {
this.websiteData.push(trackerData);
}
getData() {
return this.websiteData;
}
}
summary.component.ts (where the data should be displayed)
import { Component, OnInit } from '@angular/core';
import { TrackerService } from 'src/app/services/tracker.service';
import { TrackerData } from 'src/app/modules/tracker-data';
@Component({
selector: 'app-summary',
templateUrl: './summary.component.html',
styleUrls: ['./summary.component.scss']
})
export class SummaryComponent implements OnInit {
websiteData: TrackerData[] = [];
constructor(
private trackerService: TrackerService,
) { }
ngOnInit(): void {
}
getData(){
this.websiteData = this.trackerService.getData();
console.log(this.websiteData);
}
}