i'm new to angular and trying to do app with date filter. So here's my problem:
I'm trying to send to do tasks to the service to recieve from another component. And when i'm running the getTasks module from my service it won't returns my array. Console shows up only the function.
import { Injectable } from '@angular/core';
import { NewTaskPageComponent, ToDoTask } from './new-task-page/new-task-page.component';
import { task } from './app.component';
@Injectable({
providedIn: 'root'
})
export class TaskService {
tasks:ToDoTask[]=[];
constructor() { }
addTask(task:ToDoTask){
this.tasks.push(task);
}
getTasks():ToDoTask[]{
return this.tasks;
}
}
this is my service.ts
import {AppComponent} from '../app.component';
import { Component, OnInit } from '@angular/core';
import { TaskService } from '../task.service';
@Component({
selector: 'app-new-task-page',
templateUrl: './new-task-page.component.html',
styleUrls: ['./new-task-page.component.sass'],
providers: [TaskService]
})
export class NewTaskPageComponent implements OnInit {
newTask ?: ToDoTask;
constructor(private _taskService:TaskService){
}
ngOnInit(): void {
}
sendTask(task:string,date:string): void{
this.newTask = new ToDoTask(task,date);
this._taskService.addTask(this.newTask);
console.log(this._taskService.getTasks);
}
}
export class ToDoTask{
task: string;
date: string;
constructor(task:string,date:string){
this.task = task;
this.date = date;
}
}
and this is my component which i'm trying to send and get the data.